libsqlited: SQLiteDBMS client API
Table of contents
- Structures
- Return codes
- Connection
- sqlited_open
- sqlited_close
- 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
- 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
- Sample1
1. Structures
sqlited
sqlited_result
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_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
username:password@hostspec[:port]/dbname
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. Error and information
sqlited_error
extern char *sqlited_error;
sqlited_getmsg
const char *sqlited_getmsg( sqlited *db );
8. 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. Sample1
#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;
}