Data Structures | Defines | Typedefs | Enumerations | Functions

vlc_sql.h File Reference

Go to the source code of this file.

Data Structures

struct  sql_value_t
struct  sql_t

Defines

#define VLC_SQL_ROW   1
 Return values for the function.
#define VLC_SQL_DONE   2
#define sql_Create(a, b, c, d, e, f)   sql_Create( VLC_OBJECT(a), b, c, d, e, f )
#define sql_Destroy(a)   sql_Destroy( VLC_OBJECT( a ) )

Typedefs

typedef struct sql_t sql_t
typedef struct sql_sys_t sql_sys_t
typedef struct sql_stmt_t sql_stmt_t
typedef int(* sql_query_callback_t )(void *, int, char **, char **)

Enumerations

enum  sql_type_e {
  SQL_NULL, SQL_INT, SQL_DOUBLE, SQL_TEXT,
  SQL_BLOB
}

Functions

VLC_API sql_tsql_Create (vlc_object_t *p_this, const char *psz_name, const char *psz_host, int i_port, const char *psz_user, const char *psz_pass)
 Create a new SQL object.
VLC_API void sql_Destroy (vlc_object_t *obj)
 Destructor for p_sql object.
static int sql_QueryCallback (sql_t *p_sql, const char *psz_query, sql_query_callback_t pf_callback, void *p_opaque)
 Perform a query using a callback function.
static int sql_Query (sql_t *p_sql, const char *psz_query, char ***pppsz_result, int *pi_rows, int *pi_cols)
 Perform a query directly.
static int sql_GetTables (sql_t *p_sql, char ***pppsz_tables)
 Get database table name list.
static void sql_Free (sql_t *p_sql, char **ppsz_result)
 Free the result of a query.
static char * sql_Printf (sql_t *p_sql, const char *psz_fmt,...)
 printf-like function that can escape forbidden/reserved characters.
static char * sql_VPrintf (sql_t *p_sql, const char *psz_fmt, va_list arg)
 vprintf replacement for SQL queries, escaping forbidden characters
static int sql_BeginTransaction (sql_t *p_sql)
 Begin a SQL transaction.
static int sql_CommitTransaction (sql_t *p_sql)
 Commit a SQL transaction.
static void sql_RollbackTransaction (sql_t *p_sql)
 Rollback a SQL transaction.
static sql_stmt_tsql_Prepare (sql_t *p_sql, const char *p_fmt, int i_length)
 Prepare an sql statement.
static int sql_BindGeneric (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, int type, const sql_value_t *p_value)
 Bind arguments to a sql_stmt_t object.
static int sql_BindNull (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos)
 Bind a NULL value to a position.
static int sql_BindInteger (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, int i_int)
 Bind an integer to the statement object at some position.
static int sql_BindDouble (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, double d_dbl)
 Bind a double to the statement object at some position.
static int sql_BindText (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, char *p_fmt, int i_length)
 Bind Text to the statement.
static int sql_BindBlob (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, void *p_ptr, int i_length)
 Bind a binary object to the statement.
static int sql_Run (sql_t *p_sql, sql_stmt_t *p_stmt)
 Run the SQL statement.
static int sql_Reset (sql_t *p_sql, sql_stmt_t *p_stmt)
 Reset the SQL statement.
static int sql_Finalize (sql_t *p_sql, sql_stmt_t *p_stmt)
 Destroy the sql statement object.
static int sql_GetColumnType (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, int *type)
 Get the datatype of the result of the column.
static int sql_GetColumn (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, int type, sql_value_t *p_res)
 Get the column data.
static int sql_GetColumnInteger (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, int *pi_res)
 Get an integer from the results of a statement.
static int sql_GetColumnDouble (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, double *pd_res)
 Get a double from the results of a statement.
static int sql_GetColumnText (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, char **pp_res)
 Get some text from the results of a statement.
static int sql_GetColumnBlob (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, void **pp_res)
 Get a blob from the results of a statement.
static int sql_GetColumnSize (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col)
 Get the size of the column in bytes.

Define Documentation

#define sql_Create (   a,
  b,
  c,
  d,
  e,
  f 
)    sql_Create( VLC_OBJECT(a), b, c, d, e, f )
#define sql_Destroy (   a  )     sql_Destroy( VLC_OBJECT( a ) )
#define VLC_SQL_DONE   2
#define VLC_SQL_ROW   1

Return values for the function.

See also:
sql_Run()

Typedef Documentation

typedef int( * sql_query_callback_t)(void *, int, char **, char **)
typedef struct sql_stmt_t sql_stmt_t
typedef struct sql_sys_t sql_sys_t
typedef struct sql_t sql_t

Enumeration Type Documentation

enum sql_type_e
Enumerator:
SQL_NULL 
SQL_INT 
SQL_DOUBLE 
SQL_TEXT 
SQL_BLOB 

Function Documentation

static int sql_BeginTransaction ( sql_t p_sql  )  [inline, static]

Begin a SQL transaction.

Parameters:
p_sql The SQL object
Returns:
VLC error code or success
Note:
This function is threadsafe

References sql_t::pf_begin.

static int sql_BindBlob ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
void *  p_ptr,
int  i_length 
) [inline, static]

Bind a binary object to the statement.

Parameters:
p_sql The SQL object
p_stmt Statement Object
i_pos Position at which the parameter should be bound
p_ptr Value to be bound
i_length Size of the blob to read
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::length, sql_value_t::ptr, sql_BindGeneric(), SQL_INT, and sql_value_t::value.

static int sql_BindDouble ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
double  d_dbl 
) [inline, static]

Bind a double to the statement object at some position.

Parameters:
p_sql The SQL object
p_stmt Statement Object
i_pos Position at which the parameter should be bound
d_dbl Value to be bound
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::dbl, sql_value_t::length, sql_BindGeneric(), SQL_INT, and sql_value_t::value.

static int sql_BindGeneric ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
int  type,
const sql_value_t p_value 
) [inline, static]

Bind arguments to a sql_stmt_t object.

Parameters:
p_sql The SQL object
p_stmt Statement Object
type Data type of the value
p_value Value to be bound
i_pos Position at which the parameter should be bound
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_bind.

Referenced by sql_BindBlob(), sql_BindDouble(), sql_BindInteger(), sql_BindNull(), and sql_BindText().

static int sql_BindInteger ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
int  i_int 
) [inline, static]

Bind an integer to the statement object at some position.

Parameters:
p_sql The SQL object
p_stmt Statement Object
i_pos Position at which the parameter should be bound
i_int Value to be bound
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::i, sql_value_t::length, sql_BindGeneric(), SQL_INT, and sql_value_t::value.

static int sql_BindNull ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos 
) [inline, static]

Bind a NULL value to a position.

Parameters:
p_sql The SQL object
p_stmt Statement Object
i_pos Position at which the parameter should be bound
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_BindGeneric(), and SQL_NULL.

static int sql_BindText ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
char *  p_fmt,
int  i_length 
) [inline, static]

Bind Text to the statement.

Parameters:
p_sql The SQL object
p_stmt Statement Object
i_pos Position at which the parameter should be bound
p_fmt Value to be bound
i_length Length of text. If -ve text up to the first null char will be selected.
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::length, sql_value_t::psz, sql_BindGeneric(), SQL_TEXT, and sql_value_t::value.

static int sql_CommitTransaction ( sql_t p_sql  )  [inline, static]

Commit a SQL transaction.

Parameters:
p_sql The SQL object
Returns:
VLC error code or success
Note:
This function is threadsafe

References sql_t::pf_commit.

VLC_API sql_t* sql_Create ( vlc_object_t p_this,
const char *  psz_name,
const char *  psz_host,
int  i_port,
const char *  psz_user,
const char *  psz_pass 
)

Create a new SQL object.

Parameters:
p_this Parent object to attach the SQL object to.
psz_host URL to the database
i_port Port on which the database is running
psz_user Username to access the database
psz_pass Password for the database
Returns:
The VLC SQL object, type sql_t.

References sql_t::i_port, module_need, msg_Err, sql_t::p_module, sql_t::psz_host, sql_t::psz_pass, sql_t::psz_user, strdup(), vlc_custom_create, and vlc_object_release.

VLC_API void sql_Destroy ( vlc_object_t obj  ) 

Destructor for p_sql object.

Parameters:
obj This p_sql object
Returns:
Nothing

References module_unneed, sql_t::p_module, sql_t::psz_host, sql_t::psz_pass, sql_t::psz_user, and vlc_object_release.

static int sql_Finalize ( sql_t p_sql,
sql_stmt_t p_stmt 
) [inline, static]

Destroy the sql statement object.

This will free memory.

Parameters:
p_sql The SQL object
p_stmt The statement object
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_finalize.

static void sql_Free ( sql_t p_sql,
char **  ppsz_result 
) [inline, static]

Free the result of a query.

Parameters:
p_sql This SQL object.
ppsz_result The result of sql_Query or sql_GetTables. See above.
Returns:
Nothing.
Note:
This function is threadsafe

References sql_t::pf_free.

static int sql_GetColumn ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
int  type,
sql_value_t p_res 
) [inline, static]

Get the column data.

Parameters:
p_sql The SQL object
p_stmt The statement object
i_col The column number
type Datatype of result
p_res The structure which contains the value of the result
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_getcolumn.

static int sql_GetColumnBlob ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
void **  pp_res 
) [inline, static]

Get a blob from the results of a statement.

Parameters:
p_sql The SQL object
p_stmt The statement object
i_col The column number
pp_res Pointer of the location for result to be stored
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_getcolumn, sql_value_t::ptr, SQL_BLOB, sql_value_t::value, and VLC_SUCCESS.

static int sql_GetColumnDouble ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
double *  pd_res 
) [inline, static]

Get a double from the results of a statement.

Parameters:
p_sql The SQL object
p_stmt The statement object
i_col The column number
d_res Pointer of the location for result to be stored
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::dbl, sql_t::pf_getcolumn, SQL_DOUBLE, sql_value_t::value, and VLC_SUCCESS.

static int sql_GetColumnInteger ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
int *  pi_res 
) [inline, static]

Get an integer from the results of a statement.

Parameters:
p_sql The SQL object
p_stmt The statement object
i_col The column number
i_res Pointer of the location for result to be stored
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_value_t::i, sql_t::pf_getcolumn, SQL_INT, sql_value_t::value, and VLC_SUCCESS.

static int sql_GetColumnSize ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col 
) [inline, static]

Get the size of the column in bytes.

Parameters:
p_sql The SQL object
p_stmt The sql statement object
i_col The column
Returns:
Size of the column in bytes, excluding the zero terminator

References sql_t::pf_getcolumnsize.

static int sql_GetColumnText ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
char **  pp_res 
) [inline, static]

Get some text from the results of a statement.

Parameters:
p_sql The SQL object
p_stmt The statement object
i_col The column number
pp_res Pointer of the location for result to be stored
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_getcolumn, sql_value_t::psz, SQL_TEXT, sql_value_t::value, and VLC_SUCCESS.

static int sql_GetColumnType ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
int *  type 
) [inline, static]

Get the datatype of the result of the column.

Parameters:
p_sql The SQL object
p_stmt The sql statement object
i_col The column
type pointer to datatype of the given column
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_gettype.

static int sql_GetTables ( sql_t p_sql,
char ***  pppsz_tables 
) [inline, static]

Get database table name list.

Parameters:
p_sql This SQL object.
pppsz_tables Pointer to an array of strings. Dynamically allocated. Similar to pppsz_result of sql_Query but with only one row.
Returns:
Number of tables or <0 in case of error.
Note:
This function is threadsafe

References sql_t::pf_get_tables.

static sql_stmt_t* sql_Prepare ( sql_t p_sql,
const char *  p_fmt,
int  i_length 
) [inline, static]

Prepare an sql statement.

Parameters:
p_sql The SQL object
p_fmt SQL query string
i_length length of the string. If negative, length will be considered up to the first character equivalent to strlen(p_fmt). Otherwise the first i_length bytes will be used
Returns:
a sql_stmt_t pointer or NULL on failure

References sql_t::pf_prepare.

static char* sql_Printf ( sql_t p_sql,
const char *  psz_fmt,
  ... 
) [inline, static]

printf-like function that can escape forbidden/reserved characters.

Parameters:
p_sql This SQL object.
psz_fmt Format of the string (with q, Q and z enabled).
... Printf arguments
Returns:
Dynamically allocated string or NULL in case of error.
Note:
Refer to SQLite documentation for more details about q, Q and z.

References sql_t::pf_vmprintf, va_end(), and va_start().

static int sql_Query ( sql_t p_sql,
const char *  psz_query,
char ***  pppsz_result,
int *  pi_rows,
int *  pi_cols 
) [inline, static]

Perform a query directly.

Parameters:
p_sql This SQL object.
psz_query The SQL query string.
pppsz_result A pointer to a array of strings: result of the query. Dynamically allocated.
pi_rows Pointer to an integer that will receive the number of result rows written.
pi_cols Pointer to an integer that will receive the number of result columns written.
Returns:
VLC_SUCCESS or VLC_EGENERIC.
Note:
pppsz_result will point to an array of strings, ppsz_result. This array of strings contains actually a 2D-matrix of strings where the first row (row 0) contains the SQL table header names. *pi_rows will be the number of result rows, so that the number of text rows in ppsz_result will be (*pi_rows + 1) (because of row 0). To get result[row,col] use (*pppsz_result)[ (row+1) * (*pi_cols) + col ]. This function is threadsafe

References sql_t::pf_query.

static int sql_QueryCallback ( sql_t p_sql,
const char *  psz_query,
sql_query_callback_t  pf_callback,
void *  p_opaque 
) [inline, static]

Perform a query using a callback function.

Parameters:
p_sql This SQL object.
psz_query The SQL query string.
pf_callback A callback function that will be called for each row of the result: 1st argument is be p_opaque, 2nd argument is the number of columns, 3rd is the result columns (array of strings), 4th is the columns names (array of strings).
p_opaque Any pointer to an object you may need in the callback.
Returns:
VLC_SUCCESS or VLC_EGENERIC.
Note:
The query will not necessarily be processed in a separate thread, but it is threadsafe

References sql_t::pf_query_callback.

static int sql_Reset ( sql_t p_sql,
sql_stmt_t p_stmt 
) [inline, static]

Reset the SQL statement.

Resetting the statement will unbind all the values that were bound on this statement

Parameters:
p_sql The SQL object
p_stmt The sql statement object
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_reset.

static void sql_RollbackTransaction ( sql_t p_sql  )  [inline, static]

Rollback a SQL transaction.

Parameters:
p_sql The SQL object
Returns:
VLC error code or success
Note:
This function is threadsafe

References sql_t::pf_rollback.

static int sql_Run ( sql_t p_sql,
sql_stmt_t p_stmt 
) [inline, static]

Run the SQL statement.

If the statement fetches data, then only one row of the data is fetched at a time. Run this function again to fetch the next row.

Parameters:
p_sql The SQL object
p_stmt The statement
Returns:
VLC_SQL_DONE if done fetching all rows or there are no rows to fetch VLC_SQL_ROW if a row was fetched for this statement. VLC_EGENERIC if this function failed

References sql_t::pf_run.

static char* sql_VPrintf ( sql_t p_sql,
const char *  psz_fmt,
va_list  arg 
) [inline, static]

vprintf replacement for SQL queries, escaping forbidden characters

Parameters:
p_sql This SQL object
psz_fmt Format of the string
arg Variable list of arguments
Returns:
Dynamically allocated string or NULL in case of error.

References sql_t::pf_vmprintf.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines