sqlite_functions.h File Reference

SQLite suppporting data structures and functions. More...

#include <sqlite3.h>
#include "str_functions.h"

Go to the source code of this file.

Data Structures

struct  SQL_Result
 Data structure that holds the result of SQL functions and command. More...

Defines

SQL file access flags.
These flags are for SQLite 3.3.X and earlier, as those versions do not have following definitions.

#define SQLITE_OPEN_READONLY   0x00000001
 The database is opened for reading only.
#define SQLITE_OPEN_READWRITE   0x00000002
 The database is opened for reading and writing.
#define SQLITE_OPEN_CREATE   0x00000004
 The database is opened for reading and writing, and is creates it if it does not already exist.
SQL_Result initial parameters.
These parameters define the initial size of SQL_Result.

Change them by define -D<parameter>=<param_value> flag in CC.

#define SQL_RESULT_FIELD_CHUNK_SIZE   2048
 Chunk size for field names.
#define SQL_RESULT_FIELD_ELEMENT_COUNT   128
 Number of fields.
#define SQL_RESULT_FIELD_CONST_COUNT   0
 Number of constant fields.
#define SQL_RESULT_RESULT_CHUNK_SIZE   65536
 Chunk size for result names.
#define SQL_RESULT_RESULT_ELEMENT_COUNT   512
 Number of results.
#define SQL_RESULT_RESULT_CONST_COUNT   0
 Number of constant results.

Functions

SQL_Resultsql_result_new ()
 New a SQL_Result instance.
StringListsql_result_free (SQL_Result *sResult, gboolean freeResult)
 Free a SQL_Result instance.
int sqlite_count_matches (sqlite3 *db, const char *sqlClause, char **errMsg_ptr)
 Count the matches returned by SQL clause.
SQL_Resultsqlite_get_sql_result (sqlite3 *db, const char *sqlClause)
 Get the results of SQL clause.
SQL_Resultsqlite_get_tableNames (sqlite3 *db)
 Get the list of table names in the database.
StringListsqlite_get_fieldNames (sqlite3 *db, const char *sqlClause, int *execResult_ptr, char **errMsg_ptr)
 Get the fields of result table of a SQL clause.
char * sqlite_value_signed_text (sqlite3_value *value)
 Return the value as signed string.
char * sqlite_value_signed_text_buffer (char *buf, sqlite3_value *value)
 Store the value as signed string to provided buffer.


Detailed Description

This header file lists supporting data structures and functions of SQLite.

Define Documentation

#define SQL_RESULT_FIELD_CONST_COUNT   0

Normally you don't need to change this.

#define SQL_RESULT_RESULT_ELEMENT_COUNT   512

It should be rol_count * col_count.

#define SQLITE_OPEN_CREATE   0x00000004

This is the behavior that is always used for sqlite3_open().


Function Documentation

StringList* sql_result_free ( SQL_Result sResult,
gboolean  freeResult 
)

Parameters:
sResult SQL_Result to be freed.
freeResult TRUE for free the whole SQL_Result; while FALSE keep the sResult->resultList but free everything else.
Returns:
NULL if freeResult is TRUE; sResult->resultList if freeResult is FALSE.

SQL_Result* sql_result_new (  ) 

Returns:
the newly allocated SQL_Result instance.

int sqlite_count_matches ( sqlite3 *  db,
const char *  sqlClause,
char **  errMsg_ptr 
)

The error message passed back through the errMsg is held in memory obtained from sqlite3_malloc(). To avoid a memory leak, the calling application should call sqlite3_free() on any error message returned through the errMsg parameter when it has finished using the error message.

Parameters:
db The database.
sqlClause SQL clause.
errMsg_ptr The error message will be written here. Free it with sqlite3_free().
Returns:
0 if no matches found. Positive number is number of matched founded. Negative number is sqlite3_exec result code multiplied by -1.

StringList* sqlite_get_fieldNames ( sqlite3 *  db,
const char *  sqlClause,
int *  execResult_ptr,
char **  errMsg_ptr 
)

The result code is store in execResult_ptr, calling application should provide a int-type variable to store the result code.

The error message passed back through the errMsg is held in memory obtained from sqlite3_malloc(). To avoid a memory leak, the calling application should call sqlite3_free() on any error message returned through the errMsg parameter when it has finished using the error message.

Parameters:
db The database.
sqlClause SQL clause.
execResult_ptr The result code will be written here.
errMsg_ptr The error message will be written here.
Returns:
SQL_Result that stores the results.

SQL_Result* sqlite_get_sql_result ( sqlite3 *  db,
const char *  sqlClause 
)

Parameters:
db The database.
sqlClause SQL clause.
Returns:
SQL_Result that stores the results.

SQL_Result* sqlite_get_tableNames ( sqlite3 *  db  ) 

Parameters:
db The database.
Returns:
SQL_Result that stores the results. Specifically, in resultList.

char* sqlite_value_signed_text ( sqlite3_value *  value  ) 

sqlite3_value_text() returns unsigned char array, unfortunately, this is not expected for most of string functions. This function return the value as a signed string.

Parameters:
value the value from SQLite.
Returns:
a newly allocated signed string that stores the value. Free it with sqlite3_free().
See also:
sqlite_value_signed_text_buffer()

char* sqlite_value_signed_text_buffer ( char *  buf,
sqlite3_value *  value 
)

It is similar with sqlite3_value_text(), except developers can provide their own buffer space to s

Note:
This function does not check the buffer overflow, it is developers' responsibility to ensure the provided buffer has enough space.
Parameters:
buf the provided buffer.
value the value from SQLite.
Returns:
same as buf.
See also:
sqlite_value_signed_text()


Generated on Tue Oct 21 17:13:23 2008 for libUnihan by  doxygen 1.5.6