libsqlited: SQLiteDBMS client API
Table of contents
- Structures
- Return codes
- Connection
- sqlited_open
- sqlited_close
- sqlited_pstmt
- Query and free result
- sqlited_query
- sqlited_free_result
- Result information
- sqlited_last_insert_rowid
- sqlited_changes
- sqlited_total_changes
- sqlited_num_rows
- sqlited_num_fields
- sqlited_field_name
- sqlited_result_type
- Fetch data
- sqlited_fetch_all
- sqlited_row_seek
- sqlited_fetch_row
- sqlited_fetch_result
- sqlited_fetch_msg
- Prepared statement ( >= 0.3.1)
- sqlited_prepare
- sqlited_bind_blob
- sqlited_bind_double
- sqlited_bind_int
- sqlited_bind_int64
- sqlited_bind_null
- sqlited_bind_text
- sqlited_execute
- sqlited_reset
- sqlited_finalize
- Error and information
- sqlited_error
- sqlited_getmsg
- WebDAV ( >= 0.3.0)
- sqlited_content_put_file
- sqlited_content_put
- sqlited_content_delete
- sqlited_content_get
- sqlited_content_free
- Sample code
- Basic
- Prepared statement
- WebDAV
1. Structures
sqlited
sqlited_result
sqlited_pstmt
2. Return codes
#define SQLITED_OK 200
#define SQLITED_CONNECTED 110
#define SQLITED_CLOSED 120
#define SQLITED_REQUEST_END 130
#define SQLITED_RESPONSE_END 130
#define SQLITED_MSG 290
#define SQLITED_NOT_CONNECT 400
#define SQLITED_AUTH 401
#define SQLITED_BAD_FORMAT 403
#define SQLITED_EMPTY 404
#define SQLITED_NO_SSL 405 >= 0.4.0
#define SQLITED_ERROR 500
#define SQLITED_NOMEM 510
#define SQLITED_ERROR_SEND 520
#define SQLITED_RESULT 0
#define SQLITED_RESULT_MSG 1
#define SQLITED_RESULT_EMTPY -1
3. Connection
sqlited_open
int sqlited_open( sqlited **db, const char *conninfo );
- conninfo
[https://]username:password@hostspec[:port]/dbname
Use https:// prefix for SSL connection.
sqlited_close
void sqlited_close( sqlited *db );
4. Query and free result
sqlited_query
sqlited_result *sqlited_query( sqlited *db, const char *query );
sqlited_free_result
void sqlited_free_result( sqlited_result *result );
5. Result information
sqlited_last_insert_rowid
sqlited_int64 sqlited_last_insert_rowid( sqlited *db );
sqlited_changes
sqlited_int64 sqlited_changes( sqlited *db );
sqlited_total_changes
sqlited_int64 sqlited_total_changes( sqlited *db );
sqlited_num_rows
sqlited_int64 sqlited_num_rows( sqlited_result *result );
sqlited_num_fields
unsigned int sqlited_num_fields( sqlited_result *result );
sqlited_field_name
const char *sqlited_field_name( sqlited_result *result, unsigned int idx );
sqlited_result_type
short sqlited_result_type( sqlited_result *result );
- SQLITED_RESULT: result set contains data to fetch.
- SQLITED_RESULT_MSG: result set contains information or error messages.
- SQLITED_RESULT_EMPTY: result set is null.
6. Fetch data
sqlited_fetch_all
int sqlited_fetch_all( sqlited_result *result, char ****resultp, sqlited_int64 *nrow, unsigned int *nfield );
sqlited_row_seek
sqlited_int64 sqlited_row_seek( sqlited_result *result, sqlited_int64 seek );
sqlited_fetch_row
const char **sqlited_fetch_row( sqlited_result *result );
sqlited_fetch_result
const char *sqlited_fetch_result( sqlited_result *result, sqlited_int64 seek, unsigned int field );
sqlited_fetch_msg
const char *sqlited_fetch_msg( struct sqlited_result *result );
7. Prepared statement ( >= 0.3.1)
sqlited_prepare
int sqlited_prepare( sqlited *db, sqlited_pstmt **pstmt, const char *sql, int length );
sqlited_bind_blob
int sqlited_bind_blob( sqlited_pstmt *pstmt, int seq, const void *value, int length );
sqlited_bind_double
int sqlited_bind_double( sqlited_pstmt *pstmt, int seq, double value );
sqlited_bind_int
int sqlited_bind_int( sqlited_pstmt *pstmt, int seq, int value );
sqlited_bind_int64
int sqlited_bind_int64( sqlited_pstmt *pstmt, int seq, long long int value );
sqlited_bind_null
int sqlited_bind_null( sqlited_pstmt *pstmt, int seq );
sqlited_bind_text
int sqlited_bind_text( sqlited_pstmt *pstmt, int seq, const char *value, int length );
sqlited_execute
sqlited_result *sqlited_execute( sqlited_pstmt *pstmt );
sqlited_reset
int sqlited_reset( sqlited_pstmt *pstmt );
sqlited_finalize
int sqlited_finalize( sqlited_pstmt *pstmt );
8. Error and information
sqlited_error
extern char *sqlited_error;
sqlited_getmsg
const char *sqlited_getmsg( sqlited *db );
9. WebDAV ( >= 0.3.0)
sqlited_content_put_file
int sqlited_content_put_file( sqlited *db, const char *remote_path, const char *local_path );
sqlited_content_put
int sqlited_content_put( sqlited *db, const char *remote_path, const char *buf, size_t size );
sqlited_content_delete
int sqlited_content_delete( sqlited *db, const char *remote_path );
sqlited_content_get
int sqlited_content_get( sqlited *db, const char *remote_path, char **buf, size_t *size );
sqlited_content_free
void sqlited_content_free( char *buf );
9. Sample code
1. Basic
#include <sqlited.h>
int main( int argc, char *argv[] )
{
extern char *sqlited_error;
sqlited *db;
int res;
sqlited_result *result;
char ***table;
sqlited_int64 rows;
unsigned int fields;
res = sqlited_open( &db, "admin:password@localhost:6543/TEST" );
if ( res != SQLITED_OK )
{
printf( "%s\n", sqlited_error );
return 1;
}
result = sqlited_query( db, "SELECT * FROM test" );
if ( result != NULL )
{
if ( sqlited_result_type( result ) == SQLITED_RESULT )
{
if ( sqlited_fetch_all( result, &table, &rows, &fields ) == SQLITED_OK )
{
printf("Rows: %lld\nFields: %d\nFirst field name: %s\nValue at 0 by 0: %s\n",
rows, fields, sqlited_field_name(result, 0), table[0][0]);
/*
* Rows: number of rows
* Fields: number of fields
* First field name: name of first field
* Value at 0 by 0: value at 0 row and 0 field
*/
}
}
else
{
printf("Return message: %s\n", sqlited_fetch_msg( result ) );
}
sqlited_free_result( result );
}
sqlited_close( db );
return 0;
}
2. Prepared statement
#include <sqlited.h>
int main( int argc, char *argv[] )
{
extern char *sqlited_error;
sqlited *db;
int res;
sqlited_result *result;
char ***table;
sqlited_int64 rows;
unsigned int fields;
sqlited_pstmt *stmt;
res = sqlited_open( &db, "admin:password@localhost:6543/TEST" );
if ( res != SQLITED_OK )
{
printf( "%s\n", sqlited_error );
return 1;
}
res = sqlited_prepare( db, &stmt, "SELECT * FROM test where a=?", 28 );
if ( res != SQLITED_OK )
printf( "%s\n", sqlited_getmsg( db ) );
res = sqlited_bind_int( stmt, /* bind sequence */ 1, /* data */ 1 );
if ( res != SQLITED_OK )
printf( "%s\n", sqlited_getmsg( db ) );
result = sqlited_execute( stmt );
if ( result != NULL )
{
if ( sqlited_result_type( result ) == SQLITED_RESULT )
{
if ( sqlited_fetch_all( result, &table, &rows, &fields ) == SQLITED_OK )
{
printf("Rows: %lld\nFields: %d\nFirst field name: %s\nValue at 0 by 0: %s\n",
rows, fields, sqlited_field_name(result, 0), table[0][0]);
/*
* Rows: number of rows
* Fields: number of fields
* First field name: name of first field
* Value at 0 by 0: value at 0 row and 0 field
*/
}
}
else
{
printf("Return message: %s\n", sqlited_fetch_msg( result ) );
}
sqlited_free_result( result );
}
else
printf( "%s\n", sqlited_getmsg( db ) );
res = sqlited_reset( stmt );
if ( res != SQLITED_OK )
printf( "%s\n", sqlited_getmsg( db ) );
res = sqlited_finalize( stmt );
if ( res != SQLITED_OK )
printf( "%s\n", sqlited_getmsg( db ) );
sqlited_close( db );
return 0;
}
3. WebDAV
#include <sqlited.h>
int main( int argc, char *argv[] )
{
extern char *sqlited_error;
sqlited *db;
int res;
char *buf;
size_t size;
res = sqlited_open( &db, "admin:password@localhost:6543/TEST" );
if ( res != SQLITED_OK )
{
printf( "%s\n", sqlited_error );
return 1;
}
if ( sqlited_content_get( db, "/index.htm", &buf, &size ) == SQLITED_OK )
{
printf( "%s\n", buf );
sqlited_content_free( buf );
}
else
printf( "%s\n", sqlited_getmsg( db ) );
sqlited_close( db );
return 0;
}