VLC  2.1.0-git
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
vlc_sql.h File Reference
Include dependency graph for vlc_sql.h:

Go to the source code of this file.

Data Structures

struct  sql_value_t
struct  sql_t

Macros

#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

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.
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.

Macro Definition Documentation

#define sql_Create (   a,
  b,
  c,
  d,
  e,
 
)    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)
inlinestatic

Begin a SQL transaction.

Parameters
p_sqlThe 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 
)
inlinestatic

Bind a binary object to the statement.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
i_posPosition at which the parameter should be bound
p_ptrValue to be bound
i_lengthSize 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 
)
inlinestatic

Bind a double to the statement object at some position.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
i_posPosition at which the parameter should be bound
d_dblValue 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 
)
inlinestatic

Bind arguments to a sql_stmt_t object.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
typeData type of the value
p_valueValue to be bound
i_posPosition 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 
)
inlinestatic

Bind an integer to the statement object at some position.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
i_posPosition at which the parameter should be bound
i_intValue 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 
)
inlinestatic

Bind a NULL value to a position.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
i_posPosition 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 
)
inlinestatic

Bind Text to the statement.

Parameters
p_sqlThe SQL object
p_stmtStatement Object
i_posPosition at which the parameter should be bound
p_fmtValue to be bound
i_lengthLength 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)
inlinestatic

Commit a SQL transaction.

Parameters
p_sqlThe SQL object
Returns
VLC error code or success
Note
This function is threadsafe

References sql_t::pf_commit.

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_thisParent object to attach the SQL object to.
psz_hostURL to the database
i_portPort on which the database is running
psz_userUsername to access the database
psz_passPassword for the database
Returns
The VLC SQL object, type sql_t.
void sql_Destroy ( vlc_object_t obj)

Destructor for p_sql object.

Parameters
objThis p_sql object
Returns
Nothing
static int sql_Finalize ( sql_t p_sql,
sql_stmt_t p_stmt 
)
inlinestatic

Destroy the sql statement object.

This will free memory.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
Returns
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_finalize.

static void sql_Free ( sql_t p_sql,
char **  ppsz_result 
)
inlinestatic

Free the result of a query.

Parameters
p_sqlThis SQL object.
ppsz_resultThe 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 
)
inlinestatic

Get the column data.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
i_colThe column number
typeDatatype of result
p_resThe 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 
)
inlinestatic

Get a blob from the results of a statement.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
i_colThe column number
pp_resPointer of the location for result to be stored
Returns
VLC_SUCCESS or VLC_EGENERIC

< No error

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 
)
inlinestatic

Get a double from the results of a statement.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
i_colThe column number
d_resPointer of the location for result to be stored
Returns
VLC_SUCCESS or VLC_EGENERIC

< No error

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 
)
inlinestatic

Get an integer from the results of a statement.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
i_colThe column number
i_resPointer of the location for result to be stored
Returns
VLC_SUCCESS or VLC_EGENERIC

< No error

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 
)
inlinestatic

Get the size of the column in bytes.

Parameters
p_sqlThe SQL object
p_stmtThe sql statement object
i_colThe 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 
)
inlinestatic

Get some text from the results of a statement.

Parameters
p_sqlThe SQL object
p_stmtThe statement object
i_colThe column number
pp_resPointer of the location for result to be stored
Returns
VLC_SUCCESS or VLC_EGENERIC

< No error

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 
)
inlinestatic

Get the datatype of the result of the column.

Parameters
p_sqlThe SQL object
p_stmtThe sql statement object
i_colThe column
typepointer 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 
)
inlinestatic

Get database table name list.

Parameters
p_sqlThis SQL object.
pppsz_tablesPointer 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 
)
inlinestatic

Prepare an sql statement.

Parameters
p_sqlThe SQL object
p_fmtSQL query string
i_lengthlength of the string. If negative, length will be considered up to the first \0 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,
  ... 
)
inlinestatic

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

Parameters
p_sqlThis SQL object.
psz_fmtFormat 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.

static int sql_Query ( sql_t p_sql,
const char *  psz_query,
char ***  pppsz_result,
int *  pi_rows,
int *  pi_cols 
)
inlinestatic

Perform a query directly.

Parameters
p_sqlThis SQL object.
psz_queryThe SQL query string.
pppsz_resultA pointer to a array of strings: result of the query. Dynamically allocated.
pi_rowsPointer to an integer that will receive the number of result rows written.
pi_colsPointer 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 
)
inlinestatic

Perform a query using a callback function.

Parameters
p_sqlThis SQL object.
psz_queryThe SQL query string.
pf_callbackA 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_opaqueAny 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 
)
inlinestatic

Reset the SQL statement.

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

Parameters
p_sqlThe SQL object
p_stmtThe sql statement object
Returns
VLC_SUCCESS or VLC_EGENERIC

References sql_t::pf_reset.

static void sql_RollbackTransaction ( sql_t p_sql)
inlinestatic

Rollback a SQL transaction.

Parameters
p_sqlThe 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 
)
inlinestatic

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_sqlThe SQL object
p_stmtThe 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 
)
inlinestatic

vprintf replacement for SQL queries, escaping forbidden characters

Parameters
p_sqlThis SQL object
psz_fmtFormat of the string
argVariable list of arguments
Returns
Dynamically allocated string or NULL in case of error.

References sql_t::pf_vmprintf.