sqlite.c File Reference

Include dependency graph for sqlite.c:


Data Structures

struct  sql_sys_t
struct  sql_stmt_t

Functions

static int load (vlc_object_t *p_this)
 Load module.
static void unload (vlc_object_t *p_this)
 Unload module.
static int OpenDatabase (sql_t *p_sql)
 Open current database.
static int CloseDatabase (sql_t *p_sql)
 Close current database.
static int QueryCallback (sql_t *p_sql, const char *query, sql_query_callback_t callback, void *arg)
 SQL Query with callback.
static int Query (sql_t *p_sql, const char *query, char ***result, int *nrow, int *ncol)
 Direct SQL Query.
static int GetTables (sql_t *p_sql, char ***result)
 Get tables in database.
static void FreeResult (sql_t *p_sql, char **ppsz_result)
 Free SQL request's result.
static char * VMSprintf (const char *psz_fmt, va_list args)
 vmprintf replacement for SQLite.
static int BeginTransaction (sql_t *p_sql)
 Starts a Transaction and waits if necessary.
static int CommitTransaction (sql_t *p_sql)
 Commit a transaction.
static void RollbackTransaction (sql_t *p_sql)
 Rollback a transaction, in case of failure.
static sql_stmt_tPrepareStatement (sql_t *p_sql, const char *psz_fmt, int i_length)
 Prepare an sqlite statement.
static int BindValues (sql_t *p_sql, sql_stmt_t *p_stmt, int i_pos, unsigned int i_type, const sql_value_t *p_value)
 Bind arguments to a sql_stmt_t object.
static int StatementStep (sql_t *p_sql, sql_stmt_t *p_stmt)
 Run the SQL statement.
static int StatementReset (sql_t *p_sql, sql_stmt_t *p_stmt)
 Reset the SQL statement.
static int StatementFinalize (sql_t *p_sql, sql_stmt_t *p_stmt)
 Destroy the sql statement object.
static int GetColumnFromStatement (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 GetColumnTypeFromStatement (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col, int *pi_type)
 Get the datatype of the result of the column.
static int GetColumnSize (sql_t *p_sql, sql_stmt_t *p_stmt, int i_col)
 Get the size of the column in bytes.
int vlc_entry__main (module_t *p_module)
const char * vlc_entry_license__main (void)
static int vlc_sqlite_busy_handler (void *p_data, int i_times)
 Sqlite Busy handler.

Function Documentation

static int BeginTransaction ( sql_t p_sql  )  [static]

Starts a Transaction and waits if necessary.

Parameters:
p_sql The SQL object
Note:
This function locks the transactions on the database. Within the period of the transaction, only the calling thread may execute sql statements provided all threads use these transaction fns.

References sql_sys_t::db, sql_sys_t::lock, msg_Dbg, msg_Warn, sql_t::p_sys, sql_sys_t::trans_lock, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int BindValues ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_pos,
unsigned int  i_type,
const sql_value_t p_value 
) [static]

Bind arguments to a sql_stmt_t object.

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

References sql_sys_t::db, sql_value_t::dbl, sql_value_t::i, sql_value_t::length, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, sql_value_t::psz, sql_value_t::ptr, SQL_BLOB, SQL_DOUBLE, SQL_INT, SQL_NULL, SQL_TEXT, sql_value_t::value, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int CloseDatabase ( sql_t p_sql  )  [static]

Close current database.

Parameters:
p_sql This sql_t object
Returns:
VLC_SUCCESS You have to set and open current database first

References sql_sys_t::db, msg_Warn, sql_t::p_sys, and VLC_SUCCESS.

Referenced by unload().

static int CommitTransaction ( sql_t p_sql  )  [static]

Commit a transaction.

Parameters:
p_sql The SQL object
Note:
This function unlocks the transactions on the database Only the calling thread of "BeginTransaction" is allowed to call this method If the commit fails, the transaction lock is still held by the thread and this function may be retried or RollbackTransaction can be called
Returns:
VLC_SUCCESS or VLC_EGENERIC

This turns the auto commit on.

References sql_sys_t::db, sql_sys_t::lock, msg_Dbg, msg_Warn, sql_t::p_sys, sql_sys_t::trans_lock, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

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

Free SQL request's result.

Parameters:
p_sql This SQL object.
ppsz_result SQL result to free

References VLC_UNUSED.

Referenced by load().

static int GetColumnFromStatement ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
int  type,
sql_value_t p_res 
) [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_sys_t::db, sql_value_t::dbl, sql_value_t::i, sql_value_t::length, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, sql_value_t::psz, sql_value_t::ptr, size, SQL_BLOB, SQL_DOUBLE, SQL_INT, SQL_NULL, SQL_TEXT, strdup(), sql_value_t::value, VLC_EGENERIC, VLC_ENOMEM, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int GetColumnSize ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col 
) [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, undefined for invalid columns

References sql_sys_t::db, sql_stmt_t::p_sqlitestmt, and sql_t::p_sys.

Referenced by load().

static int GetColumnTypeFromStatement ( sql_t p_sql,
sql_stmt_t p_stmt,
int  i_col,
int *  pi_type 
) [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
pi_type pointer to datatype of the given column
Returns:
VLC_SUCCESS or VLC_EGENERIC

References sql_sys_t::db, sql_sys_t::lock, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, SQL_BLOB, SQL_DOUBLE, SQL_INT, SQL_NULL, SQL_TEXT, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int GetTables ( sql_t p_sql,
char ***  result 
) [static]

Get tables in database.

Parameters:
p_sql This sql_t object
result SQL query result
Returns:
Number of elements You have to set and open current database first

References sql_sys_t::db, sql_sys_t::lock, msg_Warn, sql_t::p_sys, vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by load().

static int load ( vlc_object_t p_this  )  [static]

static int OpenDatabase ( sql_t p_sql  )  [static]

Open current database.

Parameters:
p_sql This sql_t object
Returns:
VLC_SUCCESS or VLC_EGENERIC
Note:
p_sql->psz_host is required

References sql_sys_t::db, msg_Err, sql_t::p_sys, sql_t::psz_host, VLC_EGENERIC, vlc_sqlite_busy_handler(), and VLC_SUCCESS.

Referenced by load().

static sql_stmt_t * PrepareStatement ( sql_t p_sql,
const char *  psz_fmt,
int  i_length 
) [static]

Prepare an sqlite statement.

Returns:
statement object or NULL in case of failure

References sql_sys_t::db, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by load().

static int Query ( sql_t p_sql,
const char *  query,
char ***  result,
int *  nrow,
int *  ncol 
) [static]

Direct SQL Query.

Parameters:
p_sql This sql_t object
query SQL query
result Return value : Array of results
nrow Return value : Row number
ncol Return value : Column number
Returns:
VLC_SUCCESS or an error code You have to set and open current database first
Todo:
Handle transaction closing due to errors in sql query

References sql_sys_t::db, sql_sys_t::lock, msg_Dbg, msg_Warn, sql_t::p_sys, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int QueryCallback ( sql_t p_sql,
const char *  query,
sql_query_callback_t  callback,
void *  arg 
) [static]

SQL Query with callback.

Parameters:
p_sql This sql_t object
query SQL query
callback Callback function to receive results row by row
arg Argument to pass to callback
Returns:
VLC_SUCCESS or an error code You have to set and open current database first

References sql_sys_t::db, sql_sys_t::lock, msg_Dbg, msg_Warn, sql_t::p_sys, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static void RollbackTransaction ( sql_t p_sql  )  [static]

Rollback a transaction, in case of failure.

Parameters:
p_sql The SQL object
Returns:
VLC_SUCCESS or VLC_EGENERIC
Note:
This function unlocks the transactions on the database Only the calling thread of "BeginTransaction" is allowed to call this method If failed, if a statement in the transaction failed, it means that the transaction was automatically rolled back If failed otherwise, the engine is busy executing some queries and you must try again

References sql_sys_t::db, sql_sys_t::lock, msg_Dbg, msg_Err, sql_t::p_sys, sql_sys_t::trans_lock, vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by load().

static int StatementFinalize ( sql_t p_sql,
sql_stmt_t p_stmt 
) [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_sys_t::db, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int StatementReset ( sql_t p_sql,
sql_stmt_t p_stmt 
) [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_sys_t::db, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by load().

static int StatementStep ( sql_t p_sql,
sql_stmt_t p_stmt 
) [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_sys_t::db, sql_sys_t::lock, msg_Warn, sql_stmt_t::p_sqlitestmt, sql_t::p_sys, VLC_EGENERIC, vlc_mutex_lock(), vlc_mutex_unlock(), VLC_SQL_DONE, and VLC_SQL_ROW.

Referenced by load().

static void unload ( vlc_object_t p_this  )  [static]

Unload module.

Parameters:
obj This sql_t object
Returns:
Nothing

References CloseDatabase(), sql_sys_t::lock, sql_t::p_sys, sql_sys_t::trans_lock, and vlc_mutex_destroy().

int vlc_entry__main ( module_t p_module  ) 

const char* vlc_entry_license__main ( void   ) 

static int vlc_sqlite_busy_handler ( void *  p_data,
int  i_times 
) [static]

Sqlite Busy handler.

Parameters:
p_data sql_t object
i_times Number of times busy handler has been invoked

References msg_Warn, and msleep.

Referenced by OpenDatabase().

static char * VMSprintf ( const char *  psz_fmt,
va_list  args 
) [static]

vmprintf replacement for SQLite.

Parameters:
psz_fmt Format string
args va_list of arguments This function implements the formats q, Q and z.

References strdup().

Referenced by load().


Generated on Tue May 25 08:05:26 2010 for VLC by  doxygen 1.5.6