SQLite 3 C/C++開発インタフェースの概要(API関数)

29252 ワード

1.0   

SQLite3 SQLite       ,     SQLite 2.8.13          ,                     API. SQLite3              :

  UTF-16  .

            .

   BLOBs      .

                    ,              3.0 .            ,     API  ,             ,                   .

3.0   2.X  API    ,              .   API              "sqlite_"   "sqlite3_".           SQLite 2.X SQLite 3.0              .

    C              UTF-16              .   SQLite      void*      UTF-16      .            void*                 .

2.0 C/C++   

SQLite 3.0   83 API  ,              (#defines). (   API          .)         ,                       .                    : sqlite3_open(), sqlite3_exec(),   sqlite3_close().                 ,       sqlite3_prepare()   SQL        ,     sqlite3_step()            .  sqlite3_column_     API               .              ,   UTF-8 UTF-16    .                    SQL         .

2.1          

   typedef struct sqlite3 sqlite3;

   int sqlite3_open(const char*, sqlite3**);

   int sqlite3_open16(const void*, sqlite3**);

   int sqlite3_close(sqlite3*);

   const char *sqlite3_errmsg(sqlite3*);

   const void *sqlite3_errmsg16(sqlite3*);

   int sqlite3_errcode(sqlite3*);

sqlite3_open()             ,                sqlite3      . sqlite3_open()   sqlite3_open16()        sqlite3_open16()   UTF-16  (          )        .          , sqlite3_open16()         UTF-16  ,   sqlite3_open()       UTF-8  .

                ,                    .       PRAGMA                           .

sqlite3_errcode()            API         . sqlite3_errmsg()                    .          UTF-8      ,          SQLite API        . sqlite3_errmsg16()   sqlite3_errmsg()      ,            UTF-16         .

SQLite3       SQLite2       ,     :

#define SQLITE_OK           0   /* Successful result */

#define SQLITE_ERROR        1   /* SQL error or missing database */

#define SQLITE_INTERNAL     2   /* An internal logic error in SQLite */

#define SQLITE_PERM         3   /* Access permission denied */

#define SQLITE_ABORT        4   /* Callback routine requested an abort */

#define SQLITE_BUSY         5   /* The database file is locked */

#define SQLITE_LOCKED       6   /* A table in the database is locked */

#define SQLITE_NOMEM        7   /* A malloc() failed */

#define SQLITE_READONLY     8   /* Attempt to write a readonly database */

#define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite_interrupt() */

#define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */

#define SQLITE_CORRUPT     11   /* The database disk image is malformed */

#define SQLITE_NOTFOUND    12   /* (Internal Only) Table or record not found */

#define SQLITE_FULL        13   /* Insertion failed because database is full */

#define SQLITE_CANTOPEN    14   /* Unable to open the database file */

#define SQLITE_PROTOCOL    15   /* Database lock protocol error */

#define SQLITE_EMPTY       16   /* (Internal Only) Database table is empty */

#define SQLITE_SCHEMA      17   /* The database schema changed */

#define SQLITE_TOOBIG      18   /* Too much data for one row of a table */

#define SQLITE_CONSTRAINT  19   /* Abort due to contraint violation */

#define SQLITE_MISMATCH    20   /* Data type mismatch */

#define SQLITE_MISUSE      21   /* Library used incorrectly */

#define SQLITE_NOLFS       22   /* Uses OS features not supported on host */

#define SQLITE_AUTH        23   /* Authorization denied */

#define SQLITE_ROW         100  /* sqlite_step() has another row ready */

#define SQLITE_DONE        101  /* sqlite_step() has finished executing */

2.2    SQL   

       typedef int (*sqlite_callback)(void*,int,char**, char**);

       int sqlite3_exec(sqlite3*, const char *sql, sqlite_callback, void*, char**);

sqlite3_exec        SQLite2           .                       SQL  .             .          API   .

 SQLite3 ,sqlite3_exec      SQL           .

       typedef struct sqlite3_stmt sqlite3_stmt;

       int sqlite3_prepare(sqlite3*, const char*, int, sqlite3_stmt**, const char**);

       int sqlite3_prepare16(sqlite3*, const void*, int, sqlite3_stmt**, const void**);

       int sqlite3_finalize(sqlite3_stmt*);

       int sqlite3_reset(sqlite3_stmt*);

sqlite3_prepare      SQL                 .                       .

sqlite3_prepare()    SQL     UTF-8   .  sqlite3_prepare16()     UTF-16   .            SQL      .                        SQL     SQLite statement     ,          sqlite3_finalize()          SQL  .         ,                . sqlite3_reset()         SQL     ,          .

SQL          "?"   "?nnn"   ":aaa""nnn""aaa"       .                (       ),      sqlite3_bind         .                (   SQL        , 1  ),       "nnn"     "?nnn"     .             SQL       ,                         .              NULL .

       int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));

       int sqlite3_bind_double(sqlite3_stmt*, int, double);

       int sqlite3_bind_int(sqlite3_stmt*, int, int);

       int sqlite3_bind_int64(sqlite3_stmt*, int, long long int);

       int sqlite3_bind_null(sqlite3_stmt*, int);

       int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));

       int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int n, void(*)(void*));

       int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);

    sqlite3_bind         ,      SQL          .                .         sqlite3_reset()    .       sqlite3_reset()                .

 SQL       (           ),             :

       int sqlite3_step(sqlite3_stmt*);

  SQL          ,sqlite3_step()       SQLITE_ROW ,   SQL              SQLITE_DONE ,          .                 SQLITE_BUSY .           SQLITE_ROW,                        :

       const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);

       int sqlite3_column_bytes(sqlite3_stmt*, int iCol);

       int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);

       int sqlite3_column_count(sqlite3_stmt*);

       const char *sqlite3_column_decltype(sqlite3_stmt *, int iCol);

       const void *sqlite3_column_decltype16(sqlite3_stmt *, int iCol);

       double sqlite3_column_double(sqlite3_stmt*, int iCol);

       int sqlite3_column_int(sqlite3_stmt*, int iCol);

       long long int sqlite3_column_int64(sqlite3_stmt*, int iCol);

       const char *sqlite3_column_name(sqlite3_stmt*, int iCol);

       const void *sqlite3_column_name16(sqlite3_stmt*, int iCol);

       const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);

       const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);

       int sqlite3_column_type(sqlite3_stmt*, int iCol);

sqlite3_column_count()             . sqlite3_column_count()        sqlite3_prepare()         . sqlite3_data_count()      sqlite3_step()      ,   sqlite3_column_count()     .     sqlite3_step()      SQLITE_DONE         ,      sqlite3_data_count()     0 ,   sqlite3_column_count()               .

                sqlite3_column_***()      ,                     .            .           1        .

sqlite3_column_type()     N        .         :

       #define SQLITE_INTEGER  1

       #define SQLITE_FLOAT    2

       #define SQLITE_TEXT     3

       #define SQLITE_BLOB     4

       #define SQLITE_NULL     5

sqlite3_column_decltype()          CREATE TABLE         .                   . sqlite3_column_name()    N     . sqlite3_column_bytes()      UTF-8    BLOBs       TEXT       . sqlite3_column_bytes16()   BLOBs        ,    TEXT      UTF-16          . sqlite3_column_blob()    BLOB   . sqlite3_column_text()    UTF-8     TEXT   . sqlite3_column_text16()    UTF-16     TEXT   . sqlite3_column_int()                  . sqlite3_column_int64()     64    .   , sqlite3_column_double()      .

       sqlite3_column_type()              .               .

2.3        

                  SQL  :

   typedef struct sqlite3_value sqlite3_value;

   int sqlite3_create_function(

     sqlite3 *,

     const char *zFunctionName,

     int nArg,

     int eTextRep,

     void*,

     void (*xFunc)(sqlite3_context*,int,sqlite3_value**),

     void (*xStep)(sqlite3_context*,int,sqlite3_value**),

     void (*xFinal)(sqlite3_context*)

   );

   int sqlite3_create_function16(

     sqlite3*,

     const void *zFunctionName,

     int nArg,

     int eTextRep,

     void*,

     void (*xFunc)(sqlite3_context*,int,sqlite3_value**),

     void (*xStep)(sqlite3_context*,int,sqlite3_value**),

     void (*xFinal)(sqlite3_context*)

   );

   #define SQLITE_UTF8     1

   #define SQLITE_UTF16    2

   #define SQLITE_UTF16BE  3

   #define SQLITE_UTF16LE  4

   #define SQLITE_ANY      5

nArg                 .       0,            .   eTextRep               .                . SQLite3                        .                          .

           xFunc   ,   xStep   xFinal   NULL.           xStep   xFinal   ,    xFunc   NULL.       sqlite3_create_aggregate() API  .

sqlite3_create_function16() sqlite_create_function()                   UTF-16   ,         UTF-8.

               sqlite3_value        SQLite version 2.X       .         sqlite3_value        :

   const void *sqlite3_value_blob(sqlite3_value*);

   int sqlite3_value_bytes(sqlite3_value*);

   int sqlite3_value_bytes16(sqlite3_value*);

   double sqlite3_value_double(sqlite3_value*);

   int sqlite3_value_int(sqlite3_value*);

   long long int sqlite3_value_int64(sqlite3_value*);

   const unsigned char *sqlite3_value_text(sqlite3_value*);

   const void *sqlite3_value_text16(sqlite3_value*);

   int sqlite3_value_type(sqlite3_value*);

          API             :

   void *sqlite3_aggregate_context(sqlite3_context*, int nbyte);

   void *sqlite3_user_data(sqlite3_context*);

   void sqlite3_result_blob(sqlite3_context*, const void*, int n, void(*)(void*));

   void sqlite3_result_double(sqlite3_context*, double);

   void sqlite3_result_error(sqlite3_context*, const char*, int);

   void sqlite3_result_error16(sqlite3_context*, const void*, int);

   void sqlite3_result_int(sqlite3_context*, int);

   void sqlite3_result_int64(sqlite3_context*, long long int);

   void sqlite3_result_null(sqlite3_context*);

   void sqlite3_result_text(sqlite3_context*, const char*, int n, void(*)(void*));

   void sqlite3_result_text16(sqlite3_context*, const void*, int n, void(*)(void*));

   void sqlite3_result_value(sqlite3_context*, sqlite3_value*);

   void *sqlite3_get_auxdata(sqlite3_context*, int);

   void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*));

2.4          

                   :

   sqlite3_create_collation(sqlite3*, const char *zName, int eTextRep, void*,

      int(*xCompare)(void*,int,const void*,int,const void*));

   sqlite3_create_collation16(sqlite3*, const void *zName, int eTextRep, void*,

      int(*xCompare)(void*,int,const void*,int,const void*));

   sqlite3_collation_needed(sqlite3*, void*, 

      void(*)(void*,sqlite3*,int eTextRep,const char*));

   sqlite3_collation_needed16(sqlite3*, void*,

      void(*)(void*,sqlite3*,int eTextRep,const void*));

sqlite3_create_collation()                      .               . eTextRep              SQLITE_UTF8, SQLITE_UTF16LE, SQLITE_UTF16BE, SQLITE_ANY,                   .                        UTF-8, UTF-16LE   UTF-16BE         . sqlite3_create_collation16() sqlite3_create_collation()                  UTF-16    UTF-8.

     sqlite3_collation_needed()            ,                        .                    ,      sqlite_3_create_collation()  .                   ,  sqlite3_collation_needed   UTF-8   . sqlite3_collation_need16()    UTF-16   .