http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/code/sqlite3ext.h ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/code/sqlite3ext.h b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/code/sqlite3ext.h deleted file mode 100644 index afb689a..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/code/sqlite3ext.h +++ /dev/null @@ -1,542 +0,0 @@ -/* -** 2006 June 7 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** This header file defines the SQLite interface for use by -** shared libraries that want to be imported as extensions into -** an SQLite instance. Shared libraries that intend to be loaded -** as extensions by SQLite should #include this file instead of -** sqlite3.h. -*/ -#ifndef _SQLITE3EXT_H_ -#define _SQLITE3EXT_H_ -#include "sqlite3-binding.h" - -typedef struct sqlite3_api_routines sqlite3_api_routines; - -/* -** The following structure holds pointers to all of the SQLite API -** routines. -** -** WARNING: In order to maintain backwards compatibility, add new -** interfaces to the end of this structure only. If you insert new -** interfaces in the middle of this structure, then older different -** versions of SQLite will not be able to load each other's shared -** libraries! -*/ -struct sqlite3_api_routines { - void * (*aggregate_context)(sqlite3_context*,int nBytes); - int (*aggregate_count)(sqlite3_context*); - int (*bind_blob)(sqlite3_stmt*,int,const void*,int n,void(*)(void*)); - int (*bind_double)(sqlite3_stmt*,int,double); - int (*bind_int)(sqlite3_stmt*,int,int); - int (*bind_int64)(sqlite3_stmt*,int,sqlite_int64); - int (*bind_null)(sqlite3_stmt*,int); - int (*bind_parameter_count)(sqlite3_stmt*); - int (*bind_parameter_index)(sqlite3_stmt*,const char*zName); - const char * (*bind_parameter_name)(sqlite3_stmt*,int); - int (*bind_text)(sqlite3_stmt*,int,const char*,int n,void(*)(void*)); - int (*bind_text16)(sqlite3_stmt*,int,const void*,int,void(*)(void*)); - int (*bind_value)(sqlite3_stmt*,int,const sqlite3_value*); - int (*busy_handler)(sqlite3*,int(*)(void*,int),void*); - int (*busy_timeout)(sqlite3*,int ms); - int (*changes)(sqlite3*); - int (*close)(sqlite3*); - int (*collation_needed)(sqlite3*,void*,void(*)(void*,sqlite3*, - int eTextRep,const char*)); - int (*collation_needed16)(sqlite3*,void*,void(*)(void*,sqlite3*, - int eTextRep,const void*)); - const void * (*column_blob)(sqlite3_stmt*,int iCol); - int (*column_bytes)(sqlite3_stmt*,int iCol); - int (*column_bytes16)(sqlite3_stmt*,int iCol); - int (*column_count)(sqlite3_stmt*pStmt); - const char * (*column_database_name)(sqlite3_stmt*,int); - const void * (*column_database_name16)(sqlite3_stmt*,int); - const char * (*column_decltype)(sqlite3_stmt*,int i); - const void * (*column_decltype16)(sqlite3_stmt*,int); - double (*column_double)(sqlite3_stmt*,int iCol); - int (*column_int)(sqlite3_stmt*,int iCol); - sqlite_int64 (*column_int64)(sqlite3_stmt*,int iCol); - const char * (*column_name)(sqlite3_stmt*,int); - const void * (*column_name16)(sqlite3_stmt*,int); - const char * (*column_origin_name)(sqlite3_stmt*,int); - const void * (*column_origin_name16)(sqlite3_stmt*,int); - const char * (*column_table_name)(sqlite3_stmt*,int); - const void * (*column_table_name16)(sqlite3_stmt*,int); - const unsigned char * (*column_text)(sqlite3_stmt*,int iCol); - const void * (*column_text16)(sqlite3_stmt*,int iCol); - int (*column_type)(sqlite3_stmt*,int iCol); - sqlite3_value* (*column_value)(sqlite3_stmt*,int iCol); - void * (*commit_hook)(sqlite3*,int(*)(void*),void*); - int (*complete)(const char*sql); - int (*complete16)(const void*sql); - int (*create_collation)(sqlite3*,const char*,int,void*, - int(*)(void*,int,const void*,int,const void*)); - int (*create_collation16)(sqlite3*,const void*,int,void*, - int(*)(void*,int,const void*,int,const void*)); - int (*create_function)(sqlite3*,const char*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*)); - int (*create_function16)(sqlite3*,const void*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*)); - int (*create_module)(sqlite3*,const char*,const sqlite3_module*,void*); - int (*data_count)(sqlite3_stmt*pStmt); - sqlite3 * (*db_handle)(sqlite3_stmt*); - int (*declare_vtab)(sqlite3*,const char*); - int (*enable_shared_cache)(int); - int (*errcode)(sqlite3*db); - const char * (*errmsg)(sqlite3*); - const void * (*errmsg16)(sqlite3*); - int (*exec)(sqlite3*,const char*,sqlite3_callback,void*,char**); - int (*expired)(sqlite3_stmt*); - int (*finalize)(sqlite3_stmt*pStmt); - void (*free)(void*); - void (*free_table)(char**result); - int (*get_autocommit)(sqlite3*); - void * (*get_auxdata)(sqlite3_context*,int); - int (*get_table)(sqlite3*,const char*,char***,int*,int*,char**); - int (*global_recover)(void); - void (*interruptx)(sqlite3*); - sqlite_int64 (*last_insert_rowid)(sqlite3*); - const char * (*libversion)(void); - int (*libversion_number)(void); - void *(*malloc)(int); - char * (*mprintf)(const char*,...); - int (*open)(const char*,sqlite3**); - int (*open16)(const void*,sqlite3**); - int (*prepare)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); - int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); - void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*); - void (*progress_handler)(sqlite3*,int,int(*)(void*),void*); - void *(*realloc)(void*,int); - int (*reset)(sqlite3_stmt*pStmt); - void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_double)(sqlite3_context*,double); - void (*result_error)(sqlite3_context*,const char*,int); - void (*result_error16)(sqlite3_context*,const void*,int); - void (*result_int)(sqlite3_context*,int); - void (*result_int64)(sqlite3_context*,sqlite_int64); - void (*result_null)(sqlite3_context*); - void (*result_text)(sqlite3_context*,const char*,int,void(*)(void*)); - void (*result_text16)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_text16be)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_text16le)(sqlite3_context*,const void*,int,void(*)(void*)); - void (*result_value)(sqlite3_context*,sqlite3_value*); - void * (*rollback_hook)(sqlite3*,void(*)(void*),void*); - int (*set_authorizer)(sqlite3*,int(*)(void*,int,const char*,const char*, - const char*,const char*),void*); - void (*set_auxdata)(sqlite3_context*,int,void*,void (*)(void*)); - char * (*snprintf)(int,char*,const char*,...); - int (*step)(sqlite3_stmt*); - int (*table_column_metadata)(sqlite3*,const char*,const char*,const char*, - char const**,char const**,int*,int*,int*); - void (*thread_cleanup)(void); - int (*total_changes)(sqlite3*); - void * (*trace)(sqlite3*,void(*xTrace)(void*,const char*),void*); - int (*transfer_bindings)(sqlite3_stmt*,sqlite3_stmt*); - void * (*update_hook)(sqlite3*,void(*)(void*,int ,char const*,char const*, - sqlite_int64),void*); - void * (*user_data)(sqlite3_context*); - const void * (*value_blob)(sqlite3_value*); - int (*value_bytes)(sqlite3_value*); - int (*value_bytes16)(sqlite3_value*); - double (*value_double)(sqlite3_value*); - int (*value_int)(sqlite3_value*); - sqlite_int64 (*value_int64)(sqlite3_value*); - int (*value_numeric_type)(sqlite3_value*); - const unsigned char * (*value_text)(sqlite3_value*); - const void * (*value_text16)(sqlite3_value*); - const void * (*value_text16be)(sqlite3_value*); - const void * (*value_text16le)(sqlite3_value*); - int (*value_type)(sqlite3_value*); - char *(*vmprintf)(const char*,va_list); - /* Added ??? */ - int (*overload_function)(sqlite3*, const char *zFuncName, int nArg); - /* Added by 3.3.13 */ - int (*prepare_v2)(sqlite3*,const char*,int,sqlite3_stmt**,const char**); - int (*prepare16_v2)(sqlite3*,const void*,int,sqlite3_stmt**,const void**); - int (*clear_bindings)(sqlite3_stmt*); - /* Added by 3.4.1 */ - int (*create_module_v2)(sqlite3*,const char*,const sqlite3_module*,void*, - void (*xDestroy)(void *)); - /* Added by 3.5.0 */ - int (*bind_zeroblob)(sqlite3_stmt*,int,int); - int (*blob_bytes)(sqlite3_blob*); - int (*blob_close)(sqlite3_blob*); - int (*blob_open)(sqlite3*,const char*,const char*,const char*,sqlite3_int64, - int,sqlite3_blob**); - int (*blob_read)(sqlite3_blob*,void*,int,int); - int (*blob_write)(sqlite3_blob*,const void*,int,int); - int (*create_collation_v2)(sqlite3*,const char*,int,void*, - int(*)(void*,int,const void*,int,const void*), - void(*)(void*)); - int (*file_control)(sqlite3*,const char*,int,void*); - sqlite3_int64 (*memory_highwater)(int); - sqlite3_int64 (*memory_used)(void); - sqlite3_mutex *(*mutex_alloc)(int); - void (*mutex_enter)(sqlite3_mutex*); - void (*mutex_free)(sqlite3_mutex*); - void (*mutex_leave)(sqlite3_mutex*); - int (*mutex_try)(sqlite3_mutex*); - int (*open_v2)(const char*,sqlite3**,int,const char*); - int (*release_memory)(int); - void (*result_error_nomem)(sqlite3_context*); - void (*result_error_toobig)(sqlite3_context*); - int (*sleep)(int); - void (*soft_heap_limit)(int); - sqlite3_vfs *(*vfs_find)(const char*); - int (*vfs_register)(sqlite3_vfs*,int); - int (*vfs_unregister)(sqlite3_vfs*); - int (*xthreadsafe)(void); - void (*result_zeroblob)(sqlite3_context*,int); - void (*result_error_code)(sqlite3_context*,int); - int (*test_control)(int, ...); - void (*randomness)(int,void*); - sqlite3 *(*context_db_handle)(sqlite3_context*); - int (*extended_result_codes)(sqlite3*,int); - int (*limit)(sqlite3*,int,int); - sqlite3_stmt *(*next_stmt)(sqlite3*,sqlite3_stmt*); - const char *(*sql)(sqlite3_stmt*); - int (*status)(int,int*,int*,int); - int (*backup_finish)(sqlite3_backup*); - sqlite3_backup *(*backup_init)(sqlite3*,const char*,sqlite3*,const char*); - int (*backup_pagecount)(sqlite3_backup*); - int (*backup_remaining)(sqlite3_backup*); - int (*backup_step)(sqlite3_backup*,int); - const char *(*compileoption_get)(int); - int (*compileoption_used)(const char*); - int (*create_function_v2)(sqlite3*,const char*,int,int,void*, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*), - void(*xDestroy)(void*)); - int (*db_config)(sqlite3*,int,...); - sqlite3_mutex *(*db_mutex)(sqlite3*); - int (*db_status)(sqlite3*,int,int*,int*,int); - int (*extended_errcode)(sqlite3*); - void (*log)(int,const char*,...); - sqlite3_int64 (*soft_heap_limit64)(sqlite3_int64); - const char *(*sourceid)(void); - int (*stmt_status)(sqlite3_stmt*,int,int); - int (*strnicmp)(const char*,const char*,int); - int (*unlock_notify)(sqlite3*,void(*)(void**,int),void*); - int (*wal_autocheckpoint)(sqlite3*,int); - int (*wal_checkpoint)(sqlite3*,const char*); - void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); - int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); - int (*vtab_config)(sqlite3*,int op,...); - int (*vtab_on_conflict)(sqlite3*); - /* Version 3.7.16 and later */ - int (*close_v2)(sqlite3*); - const char *(*db_filename)(sqlite3*,const char*); - int (*db_readonly)(sqlite3*,const char*); - int (*db_release_memory)(sqlite3*); - const char *(*errstr)(int); - int (*stmt_busy)(sqlite3_stmt*); - int (*stmt_readonly)(sqlite3_stmt*); - int (*stricmp)(const char*,const char*); - int (*uri_boolean)(const char*,const char*,int); - sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); - const char *(*uri_parameter)(const char*,const char*); - char *(*vsnprintf)(int,char*,const char*,va_list); - int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); - /* Version 3.8.7 and later */ - int (*auto_extension)(void(*)(void)); - int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64, - void(*)(void*)); - int (*bind_text64)(sqlite3_stmt*,int,const char*,sqlite3_uint64, - void(*)(void*),unsigned char); - int (*cancel_auto_extension)(void(*)(void)); - int (*load_extension)(sqlite3*,const char*,const char*,char**); - void *(*malloc64)(sqlite3_uint64); - sqlite3_uint64 (*msize)(void*); - void *(*realloc64)(void*,sqlite3_uint64); - void (*reset_auto_extension)(void); - void (*result_blob64)(sqlite3_context*,const void*,sqlite3_uint64, - void(*)(void*)); - void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64, - void(*)(void*), unsigned char); - int (*strglob)(const char*,const char*); - /* Version 3.8.11 and later */ - sqlite3_value *(*value_dup)(const sqlite3_value*); - void (*value_free)(sqlite3_value*); - int (*result_zeroblob64)(sqlite3_context*,sqlite3_uint64); - int (*bind_zeroblob64)(sqlite3_stmt*, int, sqlite3_uint64); - /* Version 3.9.0 and later */ - unsigned int (*value_subtype)(sqlite3_value*); - void (*result_subtype)(sqlite3_context*,unsigned int); - /* Version 3.10.0 and later */ - int (*status64)(int,sqlite3_int64*,sqlite3_int64*,int); - int (*strlike)(const char*,const char*,unsigned int); - int (*db_cacheflush)(sqlite3*); -}; - -/* -** The following macros redefine the API routines so that they are -** redirected through the global sqlite3_api structure. -** -** This header file is also used by the loadext.c source file -** (part of the main SQLite library - not an extension) so that -** it can get access to the sqlite3_api_routines structure -** definition. But the main library does not want to redefine -** the API. So the redefinition macros are only valid if the -** SQLITE_CORE macros is undefined. -*/ -#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) -#define sqlite3_aggregate_context sqlite3_api->aggregate_context -#ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_aggregate_count sqlite3_api->aggregate_count -#endif -#define sqlite3_bind_blob sqlite3_api->bind_blob -#define sqlite3_bind_double sqlite3_api->bind_double -#define sqlite3_bind_int sqlite3_api->bind_int -#define sqlite3_bind_int64 sqlite3_api->bind_int64 -#define sqlite3_bind_null sqlite3_api->bind_null -#define sqlite3_bind_parameter_count sqlite3_api->bind_parameter_count -#define sqlite3_bind_parameter_index sqlite3_api->bind_parameter_index -#define sqlite3_bind_parameter_name sqlite3_api->bind_parameter_name -#define sqlite3_bind_text sqlite3_api->bind_text -#define sqlite3_bind_text16 sqlite3_api->bind_text16 -#define sqlite3_bind_value sqlite3_api->bind_value -#define sqlite3_busy_handler sqlite3_api->busy_handler -#define sqlite3_busy_timeout sqlite3_api->busy_timeout -#define sqlite3_changes sqlite3_api->changes -#define sqlite3_close sqlite3_api->close -#define sqlite3_collation_needed sqlite3_api->collation_needed -#define sqlite3_collation_needed16 sqlite3_api->collation_needed16 -#define sqlite3_column_blob sqlite3_api->column_blob -#define sqlite3_column_bytes sqlite3_api->column_bytes -#define sqlite3_column_bytes16 sqlite3_api->column_bytes16 -#define sqlite3_column_count sqlite3_api->column_count -#define sqlite3_column_database_name sqlite3_api->column_database_name -#define sqlite3_column_database_name16 sqlite3_api->column_database_name16 -#define sqlite3_column_decltype sqlite3_api->column_decltype -#define sqlite3_column_decltype16 sqlite3_api->column_decltype16 -#define sqlite3_column_double sqlite3_api->column_double -#define sqlite3_column_int sqlite3_api->column_int -#define sqlite3_column_int64 sqlite3_api->column_int64 -#define sqlite3_column_name sqlite3_api->column_name -#define sqlite3_column_name16 sqlite3_api->column_name16 -#define sqlite3_column_origin_name sqlite3_api->column_origin_name -#define sqlite3_column_origin_name16 sqlite3_api->column_origin_name16 -#define sqlite3_column_table_name sqlite3_api->column_table_name -#define sqlite3_column_table_name16 sqlite3_api->column_table_name16 -#define sqlite3_column_text sqlite3_api->column_text -#define sqlite3_column_text16 sqlite3_api->column_text16 -#define sqlite3_column_type sqlite3_api->column_type -#define sqlite3_column_value sqlite3_api->column_value -#define sqlite3_commit_hook sqlite3_api->commit_hook -#define sqlite3_complete sqlite3_api->complete -#define sqlite3_complete16 sqlite3_api->complete16 -#define sqlite3_create_collation sqlite3_api->create_collation -#define sqlite3_create_collation16 sqlite3_api->create_collation16 -#define sqlite3_create_function sqlite3_api->create_function -#define sqlite3_create_function16 sqlite3_api->create_function16 -#define sqlite3_create_module sqlite3_api->create_module -#define sqlite3_create_module_v2 sqlite3_api->create_module_v2 -#define sqlite3_data_count sqlite3_api->data_count -#define sqlite3_db_handle sqlite3_api->db_handle -#define sqlite3_declare_vtab sqlite3_api->declare_vtab -#define sqlite3_enable_shared_cache sqlite3_api->enable_shared_cache -#define sqlite3_errcode sqlite3_api->errcode -#define sqlite3_errmsg sqlite3_api->errmsg -#define sqlite3_errmsg16 sqlite3_api->errmsg16 -#define sqlite3_exec sqlite3_api->exec -#ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_expired sqlite3_api->expired -#endif -#define sqlite3_finalize sqlite3_api->finalize -#define sqlite3_free sqlite3_api->free -#define sqlite3_free_table sqlite3_api->free_table -#define sqlite3_get_autocommit sqlite3_api->get_autocommit -#define sqlite3_get_auxdata sqlite3_api->get_auxdata -#define sqlite3_get_table sqlite3_api->get_table -#ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_global_recover sqlite3_api->global_recover -#endif -#define sqlite3_interrupt sqlite3_api->interruptx -#define sqlite3_last_insert_rowid sqlite3_api->last_insert_rowid -#define sqlite3_libversion sqlite3_api->libversion -#define sqlite3_libversion_number sqlite3_api->libversion_number -#define sqlite3_malloc sqlite3_api->malloc -#define sqlite3_mprintf sqlite3_api->mprintf -#define sqlite3_open sqlite3_api->open -#define sqlite3_open16 sqlite3_api->open16 -#define sqlite3_prepare sqlite3_api->prepare -#define sqlite3_prepare16 sqlite3_api->prepare16 -#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 -#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 -#define sqlite3_profile sqlite3_api->profile -#define sqlite3_progress_handler sqlite3_api->progress_handler -#define sqlite3_realloc sqlite3_api->realloc -#define sqlite3_reset sqlite3_api->reset -#define sqlite3_result_blob sqlite3_api->result_blob -#define sqlite3_result_double sqlite3_api->result_double -#define sqlite3_result_error sqlite3_api->result_error -#define sqlite3_result_error16 sqlite3_api->result_error16 -#define sqlite3_result_int sqlite3_api->result_int -#define sqlite3_result_int64 sqlite3_api->result_int64 -#define sqlite3_result_null sqlite3_api->result_null -#define sqlite3_result_text sqlite3_api->result_text -#define sqlite3_result_text16 sqlite3_api->result_text16 -#define sqlite3_result_text16be sqlite3_api->result_text16be -#define sqlite3_result_text16le sqlite3_api->result_text16le -#define sqlite3_result_value sqlite3_api->result_value -#define sqlite3_rollback_hook sqlite3_api->rollback_hook -#define sqlite3_set_authorizer sqlite3_api->set_authorizer -#define sqlite3_set_auxdata sqlite3_api->set_auxdata -#define sqlite3_snprintf sqlite3_api->snprintf -#define sqlite3_step sqlite3_api->step -#define sqlite3_table_column_metadata sqlite3_api->table_column_metadata -#define sqlite3_thread_cleanup sqlite3_api->thread_cleanup -#define sqlite3_total_changes sqlite3_api->total_changes -#define sqlite3_trace sqlite3_api->trace -#ifndef SQLITE_OMIT_DEPRECATED -#define sqlite3_transfer_bindings sqlite3_api->transfer_bindings -#endif -#define sqlite3_update_hook sqlite3_api->update_hook -#define sqlite3_user_data sqlite3_api->user_data -#define sqlite3_value_blob sqlite3_api->value_blob -#define sqlite3_value_bytes sqlite3_api->value_bytes -#define sqlite3_value_bytes16 sqlite3_api->value_bytes16 -#define sqlite3_value_double sqlite3_api->value_double -#define sqlite3_value_int sqlite3_api->value_int -#define sqlite3_value_int64 sqlite3_api->value_int64 -#define sqlite3_value_numeric_type sqlite3_api->value_numeric_type -#define sqlite3_value_text sqlite3_api->value_text -#define sqlite3_value_text16 sqlite3_api->value_text16 -#define sqlite3_value_text16be sqlite3_api->value_text16be -#define sqlite3_value_text16le sqlite3_api->value_text16le -#define sqlite3_value_type sqlite3_api->value_type -#define sqlite3_vmprintf sqlite3_api->vmprintf -#define sqlite3_vsnprintf sqlite3_api->vsnprintf -#define sqlite3_overload_function sqlite3_api->overload_function -#define sqlite3_prepare_v2 sqlite3_api->prepare_v2 -#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2 -#define sqlite3_clear_bindings sqlite3_api->clear_bindings -#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob -#define sqlite3_blob_bytes sqlite3_api->blob_bytes -#define sqlite3_blob_close sqlite3_api->blob_close -#define sqlite3_blob_open sqlite3_api->blob_open -#define sqlite3_blob_read sqlite3_api->blob_read -#define sqlite3_blob_write sqlite3_api->blob_write -#define sqlite3_create_collation_v2 sqlite3_api->create_collation_v2 -#define sqlite3_file_control sqlite3_api->file_control -#define sqlite3_memory_highwater sqlite3_api->memory_highwater -#define sqlite3_memory_used sqlite3_api->memory_used -#define sqlite3_mutex_alloc sqlite3_api->mutex_alloc -#define sqlite3_mutex_enter sqlite3_api->mutex_enter -#define sqlite3_mutex_free sqlite3_api->mutex_free -#define sqlite3_mutex_leave sqlite3_api->mutex_leave -#define sqlite3_mutex_try sqlite3_api->mutex_try -#define sqlite3_open_v2 sqlite3_api->open_v2 -#define sqlite3_release_memory sqlite3_api->release_memory -#define sqlite3_result_error_nomem sqlite3_api->result_error_nomem -#define sqlite3_result_error_toobig sqlite3_api->result_error_toobig -#define sqlite3_sleep sqlite3_api->sleep -#define sqlite3_soft_heap_limit sqlite3_api->soft_heap_limit -#define sqlite3_vfs_find sqlite3_api->vfs_find -#define sqlite3_vfs_register sqlite3_api->vfs_register -#define sqlite3_vfs_unregister sqlite3_api->vfs_unregister -#define sqlite3_threadsafe sqlite3_api->xthreadsafe -#define sqlite3_result_zeroblob sqlite3_api->result_zeroblob -#define sqlite3_result_error_code sqlite3_api->result_error_code -#define sqlite3_test_control sqlite3_api->test_control -#define sqlite3_randomness sqlite3_api->randomness -#define sqlite3_context_db_handle sqlite3_api->context_db_handle -#define sqlite3_extended_result_codes sqlite3_api->extended_result_codes -#define sqlite3_limit sqlite3_api->limit -#define sqlite3_next_stmt sqlite3_api->next_stmt -#define sqlite3_sql sqlite3_api->sql -#define sqlite3_status sqlite3_api->status -#define sqlite3_backup_finish sqlite3_api->backup_finish -#define sqlite3_backup_init sqlite3_api->backup_init -#define sqlite3_backup_pagecount sqlite3_api->backup_pagecount -#define sqlite3_backup_remaining sqlite3_api->backup_remaining -#define sqlite3_backup_step sqlite3_api->backup_step -#define sqlite3_compileoption_get sqlite3_api->compileoption_get -#define sqlite3_compileoption_used sqlite3_api->compileoption_used -#define sqlite3_create_function_v2 sqlite3_api->create_function_v2 -#define sqlite3_db_config sqlite3_api->db_config -#define sqlite3_db_mutex sqlite3_api->db_mutex -#define sqlite3_db_status sqlite3_api->db_status -#define sqlite3_extended_errcode sqlite3_api->extended_errcode -#define sqlite3_log sqlite3_api->log -#define sqlite3_soft_heap_limit64 sqlite3_api->soft_heap_limit64 -#define sqlite3_sourceid sqlite3_api->sourceid -#define sqlite3_stmt_status sqlite3_api->stmt_status -#define sqlite3_strnicmp sqlite3_api->strnicmp -#define sqlite3_unlock_notify sqlite3_api->unlock_notify -#define sqlite3_wal_autocheckpoint sqlite3_api->wal_autocheckpoint -#define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint -#define sqlite3_wal_hook sqlite3_api->wal_hook -#define sqlite3_blob_reopen sqlite3_api->blob_reopen -#define sqlite3_vtab_config sqlite3_api->vtab_config -#define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict -/* Version 3.7.16 and later */ -#define sqlite3_close_v2 sqlite3_api->close_v2 -#define sqlite3_db_filename sqlite3_api->db_filename -#define sqlite3_db_readonly sqlite3_api->db_readonly -#define sqlite3_db_release_memory sqlite3_api->db_release_memory -#define sqlite3_errstr sqlite3_api->errstr -#define sqlite3_stmt_busy sqlite3_api->stmt_busy -#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly -#define sqlite3_stricmp sqlite3_api->stricmp -#define sqlite3_uri_boolean sqlite3_api->uri_boolean -#define sqlite3_uri_int64 sqlite3_api->uri_int64 -#define sqlite3_uri_parameter sqlite3_api->uri_parameter -#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf -#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 -/* Version 3.8.7 and later */ -#define sqlite3_auto_extension sqlite3_api->auto_extension -#define sqlite3_bind_blob64 sqlite3_api->bind_blob64 -#define sqlite3_bind_text64 sqlite3_api->bind_text64 -#define sqlite3_cancel_auto_extension sqlite3_api->cancel_auto_extension -#define sqlite3_load_extension sqlite3_api->load_extension -#define sqlite3_malloc64 sqlite3_api->malloc64 -#define sqlite3_msize sqlite3_api->msize -#define sqlite3_realloc64 sqlite3_api->realloc64 -#define sqlite3_reset_auto_extension sqlite3_api->reset_auto_extension -#define sqlite3_result_blob64 sqlite3_api->result_blob64 -#define sqlite3_result_text64 sqlite3_api->result_text64 -#define sqlite3_strglob sqlite3_api->strglob -/* Version 3.8.11 and later */ -#define sqlite3_value_dup sqlite3_api->value_dup -#define sqlite3_value_free sqlite3_api->value_free -#define sqlite3_result_zeroblob64 sqlite3_api->result_zeroblob64 -#define sqlite3_bind_zeroblob64 sqlite3_api->bind_zeroblob64 -/* Version 3.9.0 and later */ -#define sqlite3_value_subtype sqlite3_api->value_subtype -#define sqlite3_result_subtype sqlite3_api->result_subtype -/* Version 3.10.0 and later */ -#define sqlite3_status64 sqlite3_api->status64 -#define sqlite3_strlike sqlite3_api->strlike -#define sqlite3_db_cacheflush sqlite3_api->db_cacheflush -#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ - -#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) - /* This case when the file really is being compiled as a loadable - ** extension */ -# define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api=0; -# define SQLITE_EXTENSION_INIT2(v) sqlite3_api=v; -# define SQLITE_EXTENSION_INIT3 \ - extern const sqlite3_api_routines *sqlite3_api; -#else - /* This case when the file is being statically linked into the - ** application */ -# define SQLITE_EXTENSION_INIT1 /*no-op*/ -# define SQLITE_EXTENSION_INIT2(v) (void)v; /* unused parameter */ -# define SQLITE_EXTENSION_INIT3 /*no-op*/ -#endif - -#endif /* _SQLITE3EXT_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go deleted file mode 100644 index 597c75f..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/doc.go +++ /dev/null @@ -1,112 +0,0 @@ -/* -Package sqlite3 provides interface to SQLite3 databases. - -This works as a driver for database/sql. - -Installation - - go get github.com/mattn/go-sqlite3 - -Supported Types - -Currently, go-sqlite3 supports the following data types. - - +------------------------------+ - |go | sqlite3 | - |----------|-------------------| - |nil | null | - |int | integer | - |int64 | integer | - |float64 | float | - |bool | integer | - |[]byte | blob | - |string | text | - |time.Time | timestamp/datetime| - +------------------------------+ - -SQLite3 Extension - -You can write your own extension module for sqlite3. For example, below is an -extension for a Regexp matcher operation. - - #include <pcre.h> - #include <string.h> - #include <stdio.h> - #include <sqlite3ext.h> - - SQLITE_EXTENSION_INIT1 - static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) { - if (argc >= 2) { - const char *target = (const char *)sqlite3_value_text(argv[1]); - const char *pattern = (const char *)sqlite3_value_text(argv[0]); - const char* errstr = NULL; - int erroff = 0; - int vec[500]; - int n, rc; - pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL); - rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500); - if (rc <= 0) { - sqlite3_result_error(context, errstr, 0); - return; - } - sqlite3_result_int(context, 1); - } - } - - #ifdef _WIN32 - __declspec(dllexport) - #endif - int sqlite3_extension_init(sqlite3 *db, char **errmsg, - const sqlite3_api_routines *api) { - SQLITE_EXTENSION_INIT2(api); - return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, - (void*)db, regexp_func, NULL, NULL); - } - -It needs to be built as a so/dll shared library. And you need to register -the extension module like below. - - sql.Register("sqlite3_with_extensions", - &sqlite3.SQLiteDriver{ - Extensions: []string{ - "sqlite3_mod_regexp", - }, - }) - -Then, you can use this extension. - - rows, err := db.Query("select text from mytable where name regexp '^golang'") - -Connection Hook - -You can hook and inject your code when the connection is established. database/sql -doesn't provide a way to get native go-sqlite3 interfaces. So if you want, -you need to set ConnectHook and get the SQLiteConn. - - sql.Register("sqlite3_with_hook_example", - &sqlite3.SQLiteDriver{ - ConnectHook: func(conn *sqlite3.SQLiteConn) error { - sqlite3conn = append(sqlite3conn, conn) - return nil - }, - }) - -Go SQlite3 Extensions - -If you want to register Go functions as SQLite extension functions, -call RegisterFunction from ConnectHook. - - regex = func(re, s string) (bool, error) { - return regexp.MatchString(re, s) - } - sql.Register("sqlite3_with_go_func", - &sqlite3.SQLiteDriver{ - ConnectHook: func(conn *sqlite3.SQLiteConn) error { - return conn.RegisterFunc("regex", regex, true) - }, - }) - -See the documentation of RegisterFunc for more details. - -*/ -package sqlite3 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go deleted file mode 100644 index b910108..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error.go +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -package sqlite3 - -import "C" - -type ErrNo int - -const ErrNoMask C.int = 0xff - -type ErrNoExtended int - -type Error struct { - Code ErrNo /* The error code returned by SQLite */ - ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */ - err string /* The error string returned by sqlite3_errmsg(), - this usually contains more specific details. */ -} - -// result codes from http://www.sqlite.org/c3ref/c_abort.html -var ( - ErrError = ErrNo(1) /* SQL error or missing database */ - ErrInternal = ErrNo(2) /* Internal logic error in SQLite */ - ErrPerm = ErrNo(3) /* Access permission denied */ - ErrAbort = ErrNo(4) /* Callback routine requested an abort */ - ErrBusy = ErrNo(5) /* The database file is locked */ - ErrLocked = ErrNo(6) /* A table in the database is locked */ - ErrNomem = ErrNo(7) /* A malloc() failed */ - ErrReadonly = ErrNo(8) /* Attempt to write a readonly database */ - ErrInterrupt = ErrNo(9) /* Operation terminated by sqlite3_interrupt() */ - ErrIoErr = ErrNo(10) /* Some kind of disk I/O error occurred */ - ErrCorrupt = ErrNo(11) /* The database disk image is malformed */ - ErrNotFound = ErrNo(12) /* Unknown opcode in sqlite3_file_control() */ - ErrFull = ErrNo(13) /* Insertion failed because database is full */ - ErrCantOpen = ErrNo(14) /* Unable to open the database file */ - ErrProtocol = ErrNo(15) /* Database lock protocol error */ - ErrEmpty = ErrNo(16) /* Database is empty */ - ErrSchema = ErrNo(17) /* The database schema changed */ - ErrTooBig = ErrNo(18) /* String or BLOB exceeds size limit */ - ErrConstraint = ErrNo(19) /* Abort due to constraint violation */ - ErrMismatch = ErrNo(20) /* Data type mismatch */ - ErrMisuse = ErrNo(21) /* Library used incorrectly */ - ErrNoLFS = ErrNo(22) /* Uses OS features not supported on host */ - ErrAuth = ErrNo(23) /* Authorization denied */ - ErrFormat = ErrNo(24) /* Auxiliary database format error */ - ErrRange = ErrNo(25) /* 2nd parameter to sqlite3_bind out of range */ - ErrNotADB = ErrNo(26) /* File opened that is not a database file */ - ErrNotice = ErrNo(27) /* Notifications from sqlite3_log() */ - ErrWarning = ErrNo(28) /* Warnings from sqlite3_log() */ -) - -func (err ErrNo) Error() string { - return Error{Code: err}.Error() -} - -func (err ErrNo) Extend(by int) ErrNoExtended { - return ErrNoExtended(int(err) | (by << 8)) -} - -func (err ErrNoExtended) Error() string { - return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error() -} - -func (err Error) Error() string { - if err.err != "" { - return err.err - } - return errorString(err) -} - -// result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html -var ( - ErrIoErrRead = ErrIoErr.Extend(1) - ErrIoErrShortRead = ErrIoErr.Extend(2) - ErrIoErrWrite = ErrIoErr.Extend(3) - ErrIoErrFsync = ErrIoErr.Extend(4) - ErrIoErrDirFsync = ErrIoErr.Extend(5) - ErrIoErrTruncate = ErrIoErr.Extend(6) - ErrIoErrFstat = ErrIoErr.Extend(7) - ErrIoErrUnlock = ErrIoErr.Extend(8) - ErrIoErrRDlock = ErrIoErr.Extend(9) - ErrIoErrDelete = ErrIoErr.Extend(10) - ErrIoErrBlocked = ErrIoErr.Extend(11) - ErrIoErrNoMem = ErrIoErr.Extend(12) - ErrIoErrAccess = ErrIoErr.Extend(13) - ErrIoErrCheckReservedLock = ErrIoErr.Extend(14) - ErrIoErrLock = ErrIoErr.Extend(15) - ErrIoErrClose = ErrIoErr.Extend(16) - ErrIoErrDirClose = ErrIoErr.Extend(17) - ErrIoErrSHMOpen = ErrIoErr.Extend(18) - ErrIoErrSHMSize = ErrIoErr.Extend(19) - ErrIoErrSHMLock = ErrIoErr.Extend(20) - ErrIoErrSHMMap = ErrIoErr.Extend(21) - ErrIoErrSeek = ErrIoErr.Extend(22) - ErrIoErrDeleteNoent = ErrIoErr.Extend(23) - ErrIoErrMMap = ErrIoErr.Extend(24) - ErrIoErrGetTempPath = ErrIoErr.Extend(25) - ErrIoErrConvPath = ErrIoErr.Extend(26) - ErrLockedSharedCache = ErrLocked.Extend(1) - ErrBusyRecovery = ErrBusy.Extend(1) - ErrBusySnapshot = ErrBusy.Extend(2) - ErrCantOpenNoTempDir = ErrCantOpen.Extend(1) - ErrCantOpenIsDir = ErrCantOpen.Extend(2) - ErrCantOpenFullPath = ErrCantOpen.Extend(3) - ErrCantOpenConvPath = ErrCantOpen.Extend(4) - ErrCorruptVTab = ErrCorrupt.Extend(1) - ErrReadonlyRecovery = ErrReadonly.Extend(1) - ErrReadonlyCantLock = ErrReadonly.Extend(2) - ErrReadonlyRollback = ErrReadonly.Extend(3) - ErrReadonlyDbMoved = ErrReadonly.Extend(4) - ErrAbortRollback = ErrAbort.Extend(2) - ErrConstraintCheck = ErrConstraint.Extend(1) - ErrConstraintCommitHook = ErrConstraint.Extend(2) - ErrConstraintForeignKey = ErrConstraint.Extend(3) - ErrConstraintFunction = ErrConstraint.Extend(4) - ErrConstraintNotNull = ErrConstraint.Extend(5) - ErrConstraintPrimaryKey = ErrConstraint.Extend(6) - ErrConstraintTrigger = ErrConstraint.Extend(7) - ErrConstraintUnique = ErrConstraint.Extend(8) - ErrConstraintVTab = ErrConstraint.Extend(9) - ErrConstraintRowId = ErrConstraint.Extend(10) - ErrNoticeRecoverWAL = ErrNotice.Extend(1) - ErrNoticeRecoverRollback = ErrNotice.Extend(2) - ErrWarningAutoIndex = ErrWarning.Extend(1) -) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go deleted file mode 100644 index 1ccbe5b..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/error_test.go +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -package sqlite3 - -import ( - "database/sql" - "io/ioutil" - "os" - "path" - "testing" -) - -func TestSimpleError(t *testing.T) { - e := ErrError.Error() - if e != "SQL logic error or missing database" { - t.Error("wrong error code:" + e) - } -} - -func TestCorruptDbErrors(t *testing.T) { - dirName, err := ioutil.TempDir("", "sqlite3") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dirName) - - dbFileName := path.Join(dirName, "test.db") - f, err := os.Create(dbFileName) - if err != nil { - t.Error(err) - } - f.Write([]byte{1, 2, 3, 4, 5}) - f.Close() - - db, err := sql.Open("sqlite3", dbFileName) - if err == nil { - _, err = db.Exec("drop table foo") - } - - sqliteErr := err.(Error) - if sqliteErr.Code != ErrNotADB { - t.Error("wrong error code for corrupted DB") - } - if err.Error() == "" { - t.Error("wrong error string for corrupted DB") - } - db.Close() -} - -func TestSqlLogicErrors(t *testing.T) { - dirName, err := ioutil.TempDir("", "sqlite3") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dirName) - - dbFileName := path.Join(dirName, "test.db") - db, err := sql.Open("sqlite3", dbFileName) - if err != nil { - t.Error(err) - } - defer db.Close() - - _, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)") - if err != nil { - t.Error(err) - } - - const expectedErr = "table Foo already exists" - _, err = db.Exec("CREATE TABLE Foo (id INTEGER PRIMARY KEY)") - if err.Error() != expectedErr { - t.Errorf("Unexpected error: %s, expected %s", err.Error(), expectedErr) - } - -} - -func TestExtendedErrorCodes_ForeignKey(t *testing.T) { - dirName, err := ioutil.TempDir("", "sqlite3-err") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dirName) - - dbFileName := path.Join(dirName, "test.db") - db, err := sql.Open("sqlite3", dbFileName) - if err != nil { - t.Error(err) - } - defer db.Close() - - _, err = db.Exec("PRAGMA foreign_keys=ON;") - if err != nil { - t.Errorf("PRAGMA foreign_keys=ON: %v", err) - } - - _, err = db.Exec(`CREATE TABLE Foo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - value INTEGER NOT NULL, - ref INTEGER NULL REFERENCES Foo (id), - UNIQUE(value) - );`) - if err != nil { - t.Error(err) - } - - _, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (100, 100);") - if err == nil { - t.Error("No error!") - } else { - sqliteErr := err.(Error) - if sqliteErr.Code != ErrConstraint { - t.Errorf("Wrong basic error code: %d != %d", - sqliteErr.Code, ErrConstraint) - } - if sqliteErr.ExtendedCode != ErrConstraintForeignKey { - t.Errorf("Wrong extended error code: %d != %d", - sqliteErr.ExtendedCode, ErrConstraintForeignKey) - } - } - -} - -func TestExtendedErrorCodes_NotNull(t *testing.T) { - dirName, err := ioutil.TempDir("", "sqlite3-err") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dirName) - - dbFileName := path.Join(dirName, "test.db") - db, err := sql.Open("sqlite3", dbFileName) - if err != nil { - t.Error(err) - } - defer db.Close() - - _, err = db.Exec("PRAGMA foreign_keys=ON;") - if err != nil { - t.Errorf("PRAGMA foreign_keys=ON: %v", err) - } - - _, err = db.Exec(`CREATE TABLE Foo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - value INTEGER NOT NULL, - ref INTEGER NULL REFERENCES Foo (id), - UNIQUE(value) - );`) - if err != nil { - t.Error(err) - } - - res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);") - if err != nil { - t.Fatalf("Creating first row: %v", err) - } - - id, err := res.LastInsertId() - if err != nil { - t.Fatalf("Retrieving last insert id: %v", err) - } - - _, err = db.Exec("INSERT INTO Foo (ref) VALUES (?);", id) - if err == nil { - t.Error("No error!") - } else { - sqliteErr := err.(Error) - if sqliteErr.Code != ErrConstraint { - t.Errorf("Wrong basic error code: %d != %d", - sqliteErr.Code, ErrConstraint) - } - if sqliteErr.ExtendedCode != ErrConstraintNotNull { - t.Errorf("Wrong extended error code: %d != %d", - sqliteErr.ExtendedCode, ErrConstraintNotNull) - } - } - -} - -func TestExtendedErrorCodes_Unique(t *testing.T) { - dirName, err := ioutil.TempDir("", "sqlite3-err") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dirName) - - dbFileName := path.Join(dirName, "test.db") - db, err := sql.Open("sqlite3", dbFileName) - if err != nil { - t.Error(err) - } - defer db.Close() - - _, err = db.Exec("PRAGMA foreign_keys=ON;") - if err != nil { - t.Errorf("PRAGMA foreign_keys=ON: %v", err) - } - - _, err = db.Exec(`CREATE TABLE Foo ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - value INTEGER NOT NULL, - ref INTEGER NULL REFERENCES Foo (id), - UNIQUE(value) - );`) - if err != nil { - t.Error(err) - } - - res, err := db.Exec("INSERT INTO Foo (value) VALUES (100);") - if err != nil { - t.Fatalf("Creating first row: %v", err) - } - - id, err := res.LastInsertId() - if err != nil { - t.Fatalf("Retrieving last insert id: %v", err) - } - - _, err = db.Exec("INSERT INTO Foo (ref, value) VALUES (?, 100);", id) - if err == nil { - t.Error("No error!") - } else { - sqliteErr := err.(Error) - if sqliteErr.Code != ErrConstraint { - t.Errorf("Wrong basic error code: %d != %d", - sqliteErr.Code, ErrConstraint) - } - if sqliteErr.ExtendedCode != ErrConstraintUnique { - t.Errorf("Wrong extended error code: %d != %d", - sqliteErr.ExtendedCode, ErrConstraintUnique) - } - extended := sqliteErr.Code.Extend(3).Error() - expected := "constraint failed" - if extended != expected { - t.Errorf("Wrong basic error code: %q != %q", - extended, expected) - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.c ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.c b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.c deleted file mode 100644 index 7ca6381..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.c +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef USE_LIBSQLITE3 -# include "code/sqlite3-binding.c" -#endif - http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.h ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.h b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.h deleted file mode 100644 index d011476..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3-binding.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef USE_LIBSQLITE3 -#include "code/sqlite3-binding.h" -#else -#include <sqlite3.h> -#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3.go deleted file mode 100644 index afeb99e..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3.go +++ /dev/null @@ -1,998 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -package sqlite3 - -/* -#cgo CFLAGS: -std=gnu99 -#cgo CFLAGS: -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE -#cgo CFLAGS: -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -#include <sqlite3-binding.h> -#include <stdlib.h> -#include <string.h> - -#ifdef __CYGWIN__ -# include <errno.h> -#endif - -#ifndef SQLITE_OPEN_READWRITE -# define SQLITE_OPEN_READWRITE 0 -#endif - -#ifndef SQLITE_OPEN_FULLMUTEX -# define SQLITE_OPEN_FULLMUTEX 0 -#endif - -static int -_sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs) { -#ifdef SQLITE_OPEN_URI - return sqlite3_open_v2(filename, ppDb, flags | SQLITE_OPEN_URI, zVfs); -#else - return sqlite3_open_v2(filename, ppDb, flags, zVfs); -#endif -} - -static int -_sqlite3_bind_text(sqlite3_stmt *stmt, int n, char *p, int np) { - return sqlite3_bind_text(stmt, n, p, np, SQLITE_TRANSIENT); -} - -static int -_sqlite3_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) { - return sqlite3_bind_blob(stmt, n, p, np, SQLITE_TRANSIENT); -} - -#include <stdio.h> -#include <stdint.h> - -static int -_sqlite3_exec(sqlite3* db, const char* pcmd, long long* rowid, long long* changes) -{ - int rv = sqlite3_exec(db, pcmd, 0, 0, 0); - *rowid = (long long) sqlite3_last_insert_rowid(db); - *changes = (long long) sqlite3_changes(db); - return rv; -} - -static int -_sqlite3_step(sqlite3_stmt* stmt, long long* rowid, long long* changes) -{ - int rv = sqlite3_step(stmt); - sqlite3* db = sqlite3_db_handle(stmt); - *rowid = (long long) sqlite3_last_insert_rowid(db); - *changes = (long long) sqlite3_changes(db); - return rv; -} - -void _sqlite3_result_text(sqlite3_context* ctx, const char* s) { - sqlite3_result_text(ctx, s, -1, &free); -} - -void _sqlite3_result_blob(sqlite3_context* ctx, const void* b, int l) { - sqlite3_result_blob(ctx, b, l, SQLITE_TRANSIENT); -} - - -int _sqlite3_create_function( - sqlite3 *db, - const char *zFunctionName, - int nArg, - int eTextRep, - uintptr_t pApp, - void (*xFunc)(sqlite3_context*,int,sqlite3_value**), - void (*xStep)(sqlite3_context*,int,sqlite3_value**), - void (*xFinal)(sqlite3_context*) -) { - return sqlite3_create_function(db, zFunctionName, nArg, eTextRep, (void*) pApp, xFunc, xStep, xFinal); -} - -void callbackTrampoline(sqlite3_context*, int, sqlite3_value**); -void stepTrampoline(sqlite3_context*, int, sqlite3_value**); -void doneTrampoline(sqlite3_context*); -*/ -import "C" -import ( - "database/sql" - "database/sql/driver" - "errors" - "fmt" - "io" - "net/url" - "reflect" - "runtime" - "strconv" - "strings" - "time" - "unsafe" -) - -// Timestamp formats understood by both this module and SQLite. -// The first format in the slice will be used when saving time values -// into the database. When parsing a string from a timestamp or -// datetime column, the formats are tried in order. -var SQLiteTimestampFormats = []string{ - // By default, store timestamps with whatever timezone they come with. - // When parsed, they will be returned with the same timezone. - "2006-01-02 15:04:05.999999999-07:00", - "2006-01-02T15:04:05.999999999-07:00", - "2006-01-02 15:04:05.999999999", - "2006-01-02T15:04:05.999999999", - "2006-01-02 15:04:05", - "2006-01-02T15:04:05", - "2006-01-02 15:04", - "2006-01-02T15:04", - "2006-01-02", -} - -func init() { - sql.Register("sqlite3", &SQLiteDriver{}) -} - -// Version returns SQLite library version information. -func Version() (libVersion string, libVersionNumber int, sourceId string) { - libVersion = C.GoString(C.sqlite3_libversion()) - libVersionNumber = int(C.sqlite3_libversion_number()) - sourceId = C.GoString(C.sqlite3_sourceid()) - return libVersion, libVersionNumber, sourceId -} - -// Driver struct. -type SQLiteDriver struct { - Extensions []string - ConnectHook func(*SQLiteConn) error -} - -// Conn struct. -type SQLiteConn struct { - db *C.sqlite3 - loc *time.Location - txlock string - funcs []*functionInfo - aggregators []*aggInfo -} - -// Tx struct. -type SQLiteTx struct { - c *SQLiteConn -} - -// Stmt struct. -type SQLiteStmt struct { - c *SQLiteConn - s *C.sqlite3_stmt - nv int - nn []string - t string - closed bool - cls bool -} - -// Result struct. -type SQLiteResult struct { - id int64 - changes int64 -} - -// Rows struct. -type SQLiteRows struct { - s *SQLiteStmt - nc int - cols []string - decltype []string - cls bool -} - -type functionInfo struct { - f reflect.Value - argConverters []callbackArgConverter - variadicConverter callbackArgConverter - retConverter callbackRetConverter -} - -func (fi *functionInfo) Call(ctx *C.sqlite3_context, argv []*C.sqlite3_value) { - args, err := callbackConvertArgs(argv, fi.argConverters, fi.variadicConverter) - if err != nil { - callbackError(ctx, err) - return - } - - ret := fi.f.Call(args) - - if len(ret) == 2 && ret[1].Interface() != nil { - callbackError(ctx, ret[1].Interface().(error)) - return - } - - err = fi.retConverter(ctx, ret[0]) - if err != nil { - callbackError(ctx, err) - return - } -} - -type aggInfo struct { - constructor reflect.Value - - // Active aggregator objects for aggregations in flight. The - // aggregators are indexed by a counter stored in the aggregation - // user data space provided by sqlite. - active map[int64]reflect.Value - next int64 - - stepArgConverters []callbackArgConverter - stepVariadicConverter callbackArgConverter - - doneRetConverter callbackRetConverter -} - -func (ai *aggInfo) agg(ctx *C.sqlite3_context) (int64, reflect.Value, error) { - aggIdx := (*int64)(C.sqlite3_aggregate_context(ctx, C.int(8))) - if *aggIdx == 0 { - *aggIdx = ai.next - ret := ai.constructor.Call(nil) - if len(ret) == 2 && ret[1].Interface() != nil { - return 0, reflect.Value{}, ret[1].Interface().(error) - } - if ret[0].IsNil() { - return 0, reflect.Value{}, errors.New("aggregator constructor returned nil state") - } - ai.next++ - ai.active[*aggIdx] = ret[0] - } - return *aggIdx, ai.active[*aggIdx], nil -} - -func (ai *aggInfo) Step(ctx *C.sqlite3_context, argv []*C.sqlite3_value) { - _, agg, err := ai.agg(ctx) - if err != nil { - callbackError(ctx, err) - return - } - - args, err := callbackConvertArgs(argv, ai.stepArgConverters, ai.stepVariadicConverter) - if err != nil { - callbackError(ctx, err) - return - } - - ret := agg.MethodByName("Step").Call(args) - if len(ret) == 1 && ret[0].Interface() != nil { - callbackError(ctx, ret[0].Interface().(error)) - return - } -} - -func (ai *aggInfo) Done(ctx *C.sqlite3_context) { - idx, agg, err := ai.agg(ctx) - if err != nil { - callbackError(ctx, err) - return - } - defer func() { delete(ai.active, idx) }() - - ret := agg.MethodByName("Done").Call(nil) - if len(ret) == 2 && ret[1].Interface() != nil { - callbackError(ctx, ret[1].Interface().(error)) - return - } - - err = ai.doneRetConverter(ctx, ret[0]) - if err != nil { - callbackError(ctx, err) - return - } -} - -// Commit transaction. -func (tx *SQLiteTx) Commit() error { - _, err := tx.c.exec("COMMIT") - return err -} - -// Rollback transaction. -func (tx *SQLiteTx) Rollback() error { - _, err := tx.c.exec("ROLLBACK") - return err -} - -// RegisterFunc makes a Go function available as a SQLite function. -// -// The Go function can have arguments of the following types: any -// numeric type except complex, bool, []byte, string and -// interface{}. interface{} arguments are given the direct translation -// of the SQLite data type: int64 for INTEGER, float64 for FLOAT, -// []byte for BLOB, string for TEXT. -// -// The function can additionally be variadic, as long as the type of -// the variadic argument is one of the above. -// -// If pure is true. SQLite will assume that the function's return -// value depends only on its inputs, and make more aggressive -// optimizations in its queries. -// -// See _example/go_custom_funcs for a detailed example. -func (c *SQLiteConn) RegisterFunc(name string, impl interface{}, pure bool) error { - var fi functionInfo - fi.f = reflect.ValueOf(impl) - t := fi.f.Type() - if t.Kind() != reflect.Func { - return errors.New("Non-function passed to RegisterFunc") - } - if t.NumOut() != 1 && t.NumOut() != 2 { - return errors.New("SQLite functions must return 1 or 2 values") - } - if t.NumOut() == 2 && !t.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return errors.New("Second return value of SQLite function must be error") - } - - numArgs := t.NumIn() - if t.IsVariadic() { - numArgs-- - } - - for i := 0; i < numArgs; i++ { - conv, err := callbackArg(t.In(i)) - if err != nil { - return err - } - fi.argConverters = append(fi.argConverters, conv) - } - - if t.IsVariadic() { - conv, err := callbackArg(t.In(numArgs).Elem()) - if err != nil { - return err - } - fi.variadicConverter = conv - // Pass -1 to sqlite so that it allows any number of - // arguments. The call helper verifies that the minimum number - // of arguments is present for variadic functions. - numArgs = -1 - } - - conv, err := callbackRet(t.Out(0)) - if err != nil { - return err - } - fi.retConverter = conv - - // fi must outlast the database connection, or we'll have dangling pointers. - c.funcs = append(c.funcs, &fi) - - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - opts := C.SQLITE_UTF8 - if pure { - opts |= C.SQLITE_DETERMINISTIC - } - rv := C._sqlite3_create_function(c.db, cname, C.int(numArgs), C.int(opts), C.uintptr_t(newHandle(c, &fi)), (*[0]byte)(unsafe.Pointer(C.callbackTrampoline)), nil, nil) - if rv != C.SQLITE_OK { - return c.lastError() - } - return nil -} - -// RegisterAggregator makes a Go type available as a SQLite aggregation function. -// -// Because aggregation is incremental, it's implemented in Go with a -// type that has 2 methods: func Step(values) accumulates one row of -// data into the accumulator, and func Done() ret finalizes and -// returns the aggregate value. "values" and "ret" may be any type -// supported by RegisterFunc. -// -// RegisterAggregator takes as implementation a constructor function -// that constructs an instance of the aggregator type each time an -// aggregation begins. The constructor must return a pointer to a -// type, or an interface that implements Step() and Done(). -// -// The constructor function and the Step/Done methods may optionally -// return an error in addition to their other return values. -// -// See _example/go_custom_funcs for a detailed example. -func (c *SQLiteConn) RegisterAggregator(name string, impl interface{}, pure bool) error { - var ai aggInfo - ai.constructor = reflect.ValueOf(impl) - t := ai.constructor.Type() - if t.Kind() != reflect.Func { - return errors.New("non-function passed to RegisterAggregator") - } - if t.NumOut() != 1 && t.NumOut() != 2 { - return errors.New("SQLite aggregator constructors must return 1 or 2 values") - } - if t.NumOut() == 2 && !t.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return errors.New("Second return value of SQLite function must be error") - } - if t.NumIn() != 0 { - return errors.New("SQLite aggregator constructors must not have arguments") - } - - agg := t.Out(0) - switch agg.Kind() { - case reflect.Ptr, reflect.Interface: - default: - return errors.New("SQlite aggregator constructor must return a pointer object") - } - stepFn, found := agg.MethodByName("Step") - if !found { - return errors.New("SQlite aggregator doesn't have a Step() function") - } - step := stepFn.Type - if step.NumOut() != 0 && step.NumOut() != 1 { - return errors.New("SQlite aggregator Step() function must return 0 or 1 values") - } - if step.NumOut() == 1 && !step.Out(0).Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return errors.New("type of SQlite aggregator Step() return value must be error") - } - - stepNArgs := step.NumIn() - start := 0 - if agg.Kind() == reflect.Ptr { - // Skip over the method receiver - stepNArgs-- - start++ - } - if step.IsVariadic() { - stepNArgs-- - } - for i := start; i < start+stepNArgs; i++ { - conv, err := callbackArg(step.In(i)) - if err != nil { - return err - } - ai.stepArgConverters = append(ai.stepArgConverters, conv) - } - if step.IsVariadic() { - conv, err := callbackArg(t.In(start + stepNArgs).Elem()) - if err != nil { - return err - } - ai.stepVariadicConverter = conv - // Pass -1 to sqlite so that it allows any number of - // arguments. The call helper verifies that the minimum number - // of arguments is present for variadic functions. - stepNArgs = -1 - } - - doneFn, found := agg.MethodByName("Done") - if !found { - return errors.New("SQlite aggregator doesn't have a Done() function") - } - done := doneFn.Type - doneNArgs := done.NumIn() - if agg.Kind() == reflect.Ptr { - // Skip over the method receiver - doneNArgs-- - } - if doneNArgs != 0 { - return errors.New("SQlite aggregator Done() function must have no arguments") - } - if done.NumOut() != 1 && done.NumOut() != 2 { - return errors.New("SQLite aggregator Done() function must return 1 or 2 values") - } - if done.NumOut() == 2 && !done.Out(1).Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return errors.New("second return value of SQLite aggregator Done() function must be error") - } - - conv, err := callbackRet(done.Out(0)) - if err != nil { - return err - } - ai.doneRetConverter = conv - ai.active = make(map[int64]reflect.Value) - ai.next = 1 - - // ai must outlast the database connection, or we'll have dangling pointers. - c.aggregators = append(c.aggregators, &ai) - - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - opts := C.SQLITE_UTF8 - if pure { - opts |= C.SQLITE_DETERMINISTIC - } - rv := C._sqlite3_create_function(c.db, cname, C.int(stepNArgs), C.int(opts), C.uintptr_t(newHandle(c, &ai)), nil, (*[0]byte)(unsafe.Pointer(C.stepTrampoline)), (*[0]byte)(unsafe.Pointer(C.doneTrampoline))) - if rv != C.SQLITE_OK { - return c.lastError() - } - return nil -} - -// AutoCommit return which currently auto commit or not. -func (c *SQLiteConn) AutoCommit() bool { - return int(C.sqlite3_get_autocommit(c.db)) != 0 -} - -func (c *SQLiteConn) lastError() Error { - return Error{ - Code: ErrNo(C.sqlite3_errcode(c.db)), - ExtendedCode: ErrNoExtended(C.sqlite3_extended_errcode(c.db)), - err: C.GoString(C.sqlite3_errmsg(c.db)), - } -} - -// Implements Execer -func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) { - if len(args) == 0 { - return c.exec(query) - } - - for { - s, err := c.Prepare(query) - if err != nil { - return nil, err - } - var res driver.Result - if s.(*SQLiteStmt).s != nil { - na := s.NumInput() - if len(args) < na { - return nil, fmt.Errorf("Not enough args to execute query. Expected %d, got %d.", na, len(args)) - } - res, err = s.Exec(args[:na]) - if err != nil && err != driver.ErrSkip { - s.Close() - return nil, err - } - args = args[na:] - } - tail := s.(*SQLiteStmt).t - s.Close() - if tail == "" { - return res, nil - } - query = tail - } -} - -// Implements Queryer -func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) { - for { - s, err := c.Prepare(query) - if err != nil { - return nil, err - } - s.(*SQLiteStmt).cls = true - na := s.NumInput() - if len(args) < na { - return nil, fmt.Errorf("Not enough args to execute query. Expected %d, got %d.", na, len(args)) - } - rows, err := s.Query(args[:na]) - if err != nil && err != driver.ErrSkip { - s.Close() - return nil, err - } - args = args[na:] - tail := s.(*SQLiteStmt).t - if tail == "" { - return rows, nil - } - rows.Close() - s.Close() - query = tail - } -} - -func (c *SQLiteConn) exec(cmd string) (driver.Result, error) { - pcmd := C.CString(cmd) - defer C.free(unsafe.Pointer(pcmd)) - - var rowid, changes C.longlong - rv := C._sqlite3_exec(c.db, pcmd, &rowid, &changes) - if rv != C.SQLITE_OK { - return nil, c.lastError() - } - return &SQLiteResult{int64(rowid), int64(changes)}, nil -} - -// Begin transaction. -func (c *SQLiteConn) Begin() (driver.Tx, error) { - if _, err := c.exec(c.txlock); err != nil { - return nil, err - } - return &SQLiteTx{c}, nil -} - -func errorString(err Error) string { - return C.GoString(C.sqlite3_errstr(C.int(err.Code))) -} - -// Open database and return a new connection. -// You can specify a DSN string using a URI as the filename. -// test.db -// file:test.db?cache=shared&mode=memory -// :memory: -// file::memory: -// go-sqlite3 adds the following query parameters to those used by SQLite: -// _loc=XXX -// Specify location of time format. It's possible to specify "auto". -// _busy_timeout=XXX -// Specify value for sqlite3_busy_timeout. -// _txlock=XXX -// Specify locking behavior for transactions. XXX can be "immediate", -// "deferred", "exclusive". -func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { - if C.sqlite3_threadsafe() == 0 { - return nil, errors.New("sqlite library was not compiled for thread-safe operation") - } - - var loc *time.Location - txlock := "BEGIN" - busy_timeout := 5000 - pos := strings.IndexRune(dsn, '?') - if pos >= 1 { - params, err := url.ParseQuery(dsn[pos+1:]) - if err != nil { - return nil, err - } - - // _loc - if val := params.Get("_loc"); val != "" { - if val == "auto" { - loc = time.Local - } else { - loc, err = time.LoadLocation(val) - if err != nil { - return nil, fmt.Errorf("Invalid _loc: %v: %v", val, err) - } - } - } - - // _busy_timeout - if val := params.Get("_busy_timeout"); val != "" { - iv, err := strconv.ParseInt(val, 10, 64) - if err != nil { - return nil, fmt.Errorf("Invalid _busy_timeout: %v: %v", val, err) - } - busy_timeout = int(iv) - } - - // _txlock - if val := params.Get("_txlock"); val != "" { - switch val { - case "immediate": - txlock = "BEGIN IMMEDIATE" - case "exclusive": - txlock = "BEGIN EXCLUSIVE" - case "deferred": - txlock = "BEGIN" - default: - return nil, fmt.Errorf("Invalid _txlock: %v", val) - } - } - - if !strings.HasPrefix(dsn, "file:") { - dsn = dsn[:pos] - } - } - - var db *C.sqlite3 - name := C.CString(dsn) - defer C.free(unsafe.Pointer(name)) - rv := C._sqlite3_open_v2(name, &db, - C.SQLITE_OPEN_FULLMUTEX| - C.SQLITE_OPEN_READWRITE| - C.SQLITE_OPEN_CREATE, - nil) - if rv != 0 { - return nil, Error{Code: ErrNo(rv)} - } - if db == nil { - return nil, errors.New("sqlite succeeded without returning a database") - } - - rv = C.sqlite3_busy_timeout(db, C.int(busy_timeout)) - if rv != C.SQLITE_OK { - return nil, Error{Code: ErrNo(rv)} - } - - conn := &SQLiteConn{db: db, loc: loc, txlock: txlock} - - if len(d.Extensions) > 0 { - if err := conn.loadExtensions(d.Extensions); err != nil { - return nil, err - } - } - - if d.ConnectHook != nil { - if err := d.ConnectHook(conn); err != nil { - return nil, err - } - } - runtime.SetFinalizer(conn, (*SQLiteConn).Close) - return conn, nil -} - -// Close the connection. -func (c *SQLiteConn) Close() error { - deleteHandles(c) - rv := C.sqlite3_close_v2(c.db) - if rv != C.SQLITE_OK { - return c.lastError() - } - c.db = nil - runtime.SetFinalizer(c, nil) - return nil -} - -// Prepare the query string. Return a new statement. -func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) { - pquery := C.CString(query) - defer C.free(unsafe.Pointer(pquery)) - var s *C.sqlite3_stmt - var tail *C.char - rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail) - if rv != C.SQLITE_OK { - return nil, c.lastError() - } - var t string - if tail != nil && *tail != '\000' { - t = strings.TrimSpace(C.GoString(tail)) - } - nv := int(C.sqlite3_bind_parameter_count(s)) - var nn []string - for i := 0; i < nv; i++ { - pn := C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1))) - if len(pn) > 1 && pn[0] == '$' && 48 <= pn[1] && pn[1] <= 57 { - nn = append(nn, C.GoString(C.sqlite3_bind_parameter_name(s, C.int(i+1)))) - } - } - ss := &SQLiteStmt{c: c, s: s, nv: nv, nn: nn, t: t} - runtime.SetFinalizer(ss, (*SQLiteStmt).Close) - return ss, nil -} - -// Close the statement. -func (s *SQLiteStmt) Close() error { - if s.closed { - return nil - } - s.closed = true - if s.c == nil || s.c.db == nil { - return errors.New("sqlite statement with already closed database connection") - } - rv := C.sqlite3_finalize(s.s) - if rv != C.SQLITE_OK { - return s.c.lastError() - } - runtime.SetFinalizer(s, nil) - return nil -} - -// Return a number of parameters. -func (s *SQLiteStmt) NumInput() int { - return s.nv -} - -type bindArg struct { - n int - v driver.Value -} - -func (s *SQLiteStmt) bind(args []driver.Value) error { - rv := C.sqlite3_reset(s.s) - if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE { - return s.c.lastError() - } - - var vargs []bindArg - narg := len(args) - vargs = make([]bindArg, narg) - if len(s.nn) > 0 { - for i, v := range s.nn { - if pi, err := strconv.Atoi(v[1:]); err == nil { - vargs[i] = bindArg{pi, args[i]} - } - } - } else { - for i, v := range args { - vargs[i] = bindArg{i + 1, v} - } - } - - for _, varg := range vargs { - n := C.int(varg.n) - v := varg.v - switch v := v.(type) { - case nil: - rv = C.sqlite3_bind_null(s.s, n) - case string: - if len(v) == 0 { - b := []byte{0} - rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(0)) - } else { - b := []byte(v) - rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) - } - case int64: - rv = C.sqlite3_bind_int64(s.s, n, C.sqlite3_int64(v)) - case bool: - if bool(v) { - rv = C.sqlite3_bind_int(s.s, n, 1) - } else { - rv = C.sqlite3_bind_int(s.s, n, 0) - } - case float64: - rv = C.sqlite3_bind_double(s.s, n, C.double(v)) - case []byte: - if len(v) == 0 { - rv = C._sqlite3_bind_blob(s.s, n, nil, 0) - } else { - rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(len(v))) - } - case time.Time: - b := []byte(v.Format(SQLiteTimestampFormats[0])) - rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) - } - if rv != C.SQLITE_OK { - return s.c.lastError() - } - } - return nil -} - -// Query the statement with arguments. Return records. -func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) { - if err := s.bind(args); err != nil { - return nil, err - } - return &SQLiteRows{s, int(C.sqlite3_column_count(s.s)), nil, nil, s.cls}, nil -} - -// Return last inserted ID. -func (r *SQLiteResult) LastInsertId() (int64, error) { - return r.id, nil -} - -// Return how many rows affected. -func (r *SQLiteResult) RowsAffected() (int64, error) { - return r.changes, nil -} - -// Execute the statement with arguments. Return result object. -func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) { - if err := s.bind(args); err != nil { - C.sqlite3_reset(s.s) - C.sqlite3_clear_bindings(s.s) - return nil, err - } - var rowid, changes C.longlong - rv := C._sqlite3_step(s.s, &rowid, &changes) - if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE { - err := s.c.lastError() - C.sqlite3_reset(s.s) - C.sqlite3_clear_bindings(s.s) - return nil, err - } - return &SQLiteResult{int64(rowid), int64(changes)}, nil -} - -// Close the rows. -func (rc *SQLiteRows) Close() error { - if rc.s.closed { - return nil - } - if rc.cls { - return rc.s.Close() - } - rv := C.sqlite3_reset(rc.s.s) - if rv != C.SQLITE_OK { - return rc.s.c.lastError() - } - return nil -} - -// Return column names. -func (rc *SQLiteRows) Columns() []string { - if rc.nc != len(rc.cols) { - rc.cols = make([]string, rc.nc) - for i := 0; i < rc.nc; i++ { - rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i))) - } - } - return rc.cols -} - -// Return column types. -func (rc *SQLiteRows) DeclTypes() []string { - if rc.decltype == nil { - rc.decltype = make([]string, rc.nc) - for i := 0; i < rc.nc; i++ { - rc.decltype[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i)))) - } - } - return rc.decltype -} - -// Move cursor to next. -func (rc *SQLiteRows) Next(dest []driver.Value) error { - rv := C.sqlite3_step(rc.s.s) - if rv == C.SQLITE_DONE { - return io.EOF - } - if rv != C.SQLITE_ROW { - rv = C.sqlite3_reset(rc.s.s) - if rv != C.SQLITE_OK { - return rc.s.c.lastError() - } - return nil - } - - rc.DeclTypes() - - for i := range dest { - switch C.sqlite3_column_type(rc.s.s, C.int(i)) { - case C.SQLITE_INTEGER: - val := int64(C.sqlite3_column_int64(rc.s.s, C.int(i))) - switch rc.decltype[i] { - case "timestamp", "datetime", "date": - var t time.Time - // Assume a millisecond unix timestamp if it's 13 digits -- too - // large to be a reasonable timestamp in seconds. - if val > 1e12 || val < -1e12 { - val *= int64(time.Millisecond) // convert ms to nsec - } else { - val *= int64(time.Second) // convert sec to nsec - } - t = time.Unix(0, val).UTC() - if rc.s.c.loc != nil { - t = t.In(rc.s.c.loc) - } - dest[i] = t - case "boolean": - dest[i] = val > 0 - default: - dest[i] = val - } - case C.SQLITE_FLOAT: - dest[i] = float64(C.sqlite3_column_double(rc.s.s, C.int(i))) - case C.SQLITE_BLOB: - p := C.sqlite3_column_blob(rc.s.s, C.int(i)) - if p == nil { - dest[i] = nil - continue - } - n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i))) - switch dest[i].(type) { - case sql.RawBytes: - dest[i] = (*[1 << 30]byte)(unsafe.Pointer(p))[0:n] - default: - slice := make([]byte, n) - copy(slice[:], (*[1 << 30]byte)(unsafe.Pointer(p))[0:n]) - dest[i] = slice - } - case C.SQLITE_NULL: - dest[i] = nil - case C.SQLITE_TEXT: - var err error - var timeVal time.Time - - n := int(C.sqlite3_column_bytes(rc.s.s, C.int(i))) - s := C.GoStringN((*C.char)(unsafe.Pointer(C.sqlite3_column_text(rc.s.s, C.int(i)))), C.int(n)) - - switch rc.decltype[i] { - case "timestamp", "datetime", "date": - var t time.Time - s = strings.TrimSuffix(s, "Z") - for _, format := range SQLiteTimestampFormats { - if timeVal, err = time.ParseInLocation(format, s, time.UTC); err == nil { - t = timeVal - break - } - } - if err != nil { - // The column is a time value, so return the zero time on parse failure. - t = time.Time{} - } - if rc.s.c.loc != nil { - t = t.In(rc.s.c.loc) - } - dest[i] = t - default: - dest[i] = []byte(s) - } - - } - } - return nil -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go deleted file mode 100644 index 803afbd..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts3_test.go +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2015 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -package sqlite3 - -import ( - "database/sql" - "os" - "testing" -) - -func TestFTS3(t *testing.T) { - tempFilename := TempFilename(t) - defer os.Remove(tempFilename) - db, err := sql.Open("sqlite3", tempFilename) - if err != nil { - t.Fatal("Failed to open database:", err) - } - defer db.Close() - - _, err = db.Exec("DROP TABLE foo") - _, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts3(id INTEGER PRIMARY KEY, value TEXT)") - if err != nil { - t.Fatal("Failed to create table:", err) - } - - _, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `仿¥ã® æ©å¾¡é£¯ã¯ å¤©éº©ç¾ ã`) - if err != nil { - t.Fatal("Failed to insert value:", err) - } - - _, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 2, `仿¥ã¯ ãã 天æ°ã `) - if err != nil { - t.Fatal("Failed to insert value:", err) - } - - rows, err := db.Query("SELECT id, value FROM foo WHERE value MATCH '仿¥* 天*'") - if err != nil { - t.Fatal("Unable to query foo table:", err) - } - defer rows.Close() - - for rows.Next() { - var id int - var value string - - if err := rows.Scan(&id, &value); err != nil { - t.Error("Unable to scan results:", err) - continue - } - - if id == 1 && value != `仿¥ã® æ©å¾¡é£¯ã¯ å¤©éº©ç¾ ã` { - t.Error("Value for id 1 should be `仿¥ã® æ©å¾¡é£¯ã¯ å¤©éº©ç¾ ã`, but:", value) - } else if id == 2 && value != `仿¥ã¯ ãã 天æ°ã ` { - t.Error("Value for id 2 should be `仿¥ã¯ ãã 天æ°ã `, but:", value) - } - } - - rows, err = db.Query("SELECT value FROM foo WHERE value MATCH '仿¥* å¤©éº©ç¾ *'") - if err != nil { - t.Fatal("Unable to query foo table:", err) - } - defer rows.Close() - - var value string - if !rows.Next() { - t.Fatal("Result should be only one") - } - - if err := rows.Scan(&value); err != nil { - t.Fatal("Unable to scan results:", err) - } - - if value != `仿¥ã® æ©å¾¡é£¯ã¯ å¤©éº©ç¾ ã` { - t.Fatal("Value should be `仿¥ã® æ©å¾¡é£¯ã¯ å¤©éº©ç¾ ã`, but:", value) - } - - if rows.Next() { - t.Fatal("Result should be only one") - } -} - -func TestFTS4(t *testing.T) { - tempFilename := TempFilename(t) - defer os.Remove(tempFilename) - db, err := sql.Open("sqlite3", tempFilename) - if err != nil { - t.Fatal("Failed to open database:", err) - } - defer db.Close() - - _, err = db.Exec("DROP TABLE foo") - _, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts4(tokenize=unicode61, id INTEGER PRIMARY KEY, value TEXT)") - if err != nil { - t.Fatal("Failed to create table:", err) - } - - _, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `février`) - if err != nil { - t.Fatal("Failed to insert value:", err) - } - - rows, err := db.Query("SELECT value FROM foo WHERE value MATCH 'fevrier'") - if err != nil { - t.Fatal("Unable to query foo table:", err) - } - defer rows.Close() - - var value string - if !rows.Next() { - t.Fatal("Result should be only one") - } - - if err := rows.Scan(&value); err != nil { - t.Fatal("Unable to scan results:", err) - } - - if value != `février` { - t.Fatal("Value should be `février`, but:", value) - } - - if rows.Next() { - t.Fatal("Result should be only one") - } -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts5.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts5.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts5.go deleted file mode 100644 index 0e65d69..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_fts5.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build fts5 - -package sqlite3 - -/* -#cgo CFLAGS: -DSQLITE_ENABLE_FTS5 -#cgo LDFLAGS: -lm -*/ -import "C" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_icu.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_icu.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_icu.go deleted file mode 100644 index 4c5492b..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_icu.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build icu - -package sqlite3 - -/* -#cgo LDFLAGS: -licuuc -licui18n -#cgo CFLAGS: -DSQLITE_ENABLE_ICU -*/ -import "C" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_json1.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_json1.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_json1.go deleted file mode 100644 index a7b2473..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_json1.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build json1 - -package sqlite3 - -/* -#cgo CFLAGS: -DSQLITE_ENABLE_JSON1 -*/ -import "C" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go deleted file mode 100644 index 0c4c557..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build libsqlite3 - -package sqlite3 - -/* -#cgo CFLAGS: -DUSE_LIBSQLITE3 -#cgo LDFLAGS: -lsqlite3 -*/ -import "C" http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_load_extension.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_load_extension.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_load_extension.go deleted file mode 100644 index 0251016..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_load_extension.go +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build !sqlite_omit_load_extension - -package sqlite3 - -/* -#include <sqlite3-binding.h> -#include <stdlib.h> -*/ -import "C" -import ( - "errors" - "unsafe" -) - -func (c *SQLiteConn) loadExtensions(extensions []string) error { - rv := C.sqlite3_enable_load_extension(c.db, 1) - if rv != C.SQLITE_OK { - return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) - } - - for _, extension := range extensions { - cext := C.CString(extension) - defer C.free(unsafe.Pointer(cext)) - rv = C.sqlite3_load_extension(c.db, cext, nil, nil) - if rv != C.SQLITE_OK { - return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) - } - } - - rv = C.sqlite3_enable_load_extension(c.db, 0) - if rv != C.SQLITE_OK { - return errors.New(C.GoString(C.sqlite3_errmsg(c.db))) - } - return nil -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_omit_load_extension.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_omit_load_extension.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_omit_load_extension.go deleted file mode 100644 index a80cf87..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_omit_load_extension.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build sqlite_omit_load_extension - -package sqlite3 - -/* -#cgo CFLAGS: -DSQLITE_OMIT_LOAD_EXTENSION -*/ -import "C" -import ( - "errors" -) - -func (c *SQLiteConn) loadExtensions(extensions []string) error { - return errors.New("Extensions have been disabled for static builds") -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b002dd0c/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_other.go ---------------------------------------------------------------------- diff --git a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_other.go b/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_other.go deleted file mode 100644 index a20d02c..0000000 --- a/newt/Godeps/_workspace/src/github.com/mattn/go-sqlite3/sqlite3_other.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>. -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. -// +build !windows - -package sqlite3 - -/* -#cgo CFLAGS: -I. -#cgo linux LDFLAGS: -ldl -*/ -import "C"
