⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlite.h

📁 sqlite数据库管理系统开放源码
💻 H
📖 第 1 页 / 共 3 页
字号:
/*** This next routine is really just a wrapper around sqlite_exec().** Instead of invoking a user-supplied callback for each row of the** result, this routine remembers each row of the result in memory** obtained from malloc(), then returns all of the result after the** query has finished. **** As an example, suppose the query result where this table:****        Name        | Age**        -----------------------**        Alice       | 43**        Bob         | 28**        Cindy       | 21**** If the 3rd argument were &azResult then after the function returns** azResult will contain the following data:****        azResult[0] = "Name";**        azResult[1] = "Age";**        azResult[2] = "Alice";**        azResult[3] = "43";**        azResult[4] = "Bob";**        azResult[5] = "28";**        azResult[6] = "Cindy";**        azResult[7] = "21";**** Notice that there is an extra row of data containing the column** headers.  But the *nrow return value is still 3.  *ncolumn is** set to 2.  In general, the number of values inserted into azResult** will be ((*nrow) + 1)*(*ncolumn).**** After the calling function has finished using the result, it should ** pass the result data pointer to sqlite_free_table() in order to ** release the memory that was malloc-ed.  Because of the way the ** malloc() happens, the calling function must not try to call ** malloc() directly.  Only sqlite_free_table() is able to release ** the memory properly and safely.**** The return value of this routine is the same as from sqlite_exec().*/int sqlite_get_table(  sqlite*,               /* An open database */  const char *sql,       /* SQL to be executed */  char ***resultp,       /* Result written to a char *[]  that this points to */  int *nrow,             /* Number of result rows written here */  int *ncolumn,          /* Number of result columns written here */  char **errmsg          /* Error msg written here */);/*** Call this routine to free the memory that sqlite_get_table() allocated.*/void sqlite_free_table(char **result);/*** The following routines are wrappers around sqlite_exec() and** sqlite_get_table().  The only difference between the routines that** follow and the originals is that the second argument to the ** routines that follow is really a printf()-style format** string describing the SQL to be executed.  Arguments to the format** string appear at the end of the argument list.**** All of the usual printf formatting options apply.  In addition, there** is a "%q" option.  %q works like %s in that it substitutes a null-terminated** string from the argument list.  But %q also doubles every '\'' character.** %q is designed for use inside a string literal.  By doubling each '\''** character it escapes that character and allows it to be inserted into** the string.**** For example, so some string variable contains text as follows:****      char *zText = "It's a happy day!";**** We can use this text in an SQL statement as follows:****      sqlite_exec_printf(db, "INSERT INTO table VALUES('%q')",**          callback1, 0, 0, zText);**** Because the %q format string is used, the '\'' character in zText** is escaped and the SQL generated is as follows:****      INSERT INTO table1 VALUES('It''s a happy day!')**** This is correct.  Had we used %s instead of %q, the generated SQL** would have looked like this:****      INSERT INTO table1 VALUES('It's a happy day!');**** This second example is an SQL syntax error.  As a general rule you** should always use %q instead of %s when inserting text into a string ** literal.*/int sqlite_exec_printf(  sqlite*,                      /* An open database */  const char *sqlFormat,        /* printf-style format string for the SQL */  sqlite_callback,              /* Callback function */  void *,                       /* 1st argument to callback function */  char **errmsg,                /* Error msg written here */  ...                           /* Arguments to the format string. */);int sqlite_exec_vprintf(  sqlite*,                      /* An open database */  const char *sqlFormat,        /* printf-style format string for the SQL */  sqlite_callback,              /* Callback function */  void *,                       /* 1st argument to callback function */  char **errmsg,                /* Error msg written here */  va_list ap                    /* Arguments to the format string. */);int sqlite_get_table_printf(  sqlite*,               /* An open database */  const char *sqlFormat, /* printf-style format string for the SQL */  char ***resultp,       /* Result written to a char *[]  that this points to */  int *nrow,             /* Number of result rows written here */  int *ncolumn,          /* Number of result columns written here */  char **errmsg,         /* Error msg written here */  ...                    /* Arguments to the format string */);int sqlite_get_table_vprintf(  sqlite*,               /* An open database */  const char *sqlFormat, /* printf-style format string for the SQL */  char ***resultp,       /* Result written to a char *[]  that this points to */  int *nrow,             /* Number of result rows written here */  int *ncolumn,          /* Number of result columns written here */  char **errmsg,         /* Error msg written here */  va_list ap             /* Arguments to the format string */);char *sqlite_mprintf(const char*,...);char *sqlite_vmprintf(const char*, va_list);/*** Windows systems should call this routine to free memory that** is returned in the in the errmsg parameter of sqlite_open() when** SQLite is a DLL.  For some reason, it does not work to call free()** directly.*/void sqlite_freemem(void *p);/*** Windows systems need functions to call to return the sqlite_version** and sqlite_encoding strings.*/const char *sqlite_libversion(void);const char *sqlite_libencoding(void);/*** A pointer to the following structure is used to communicate with** the implementations of user-defined functions.*/typedef struct sqlite_func sqlite_func;/*** Use the following routines to create new user-defined functions.  See** the documentation for details.*/int sqlite_create_function(  sqlite*,                  /* Database where the new function is registered */  const char *zName,        /* Name of the new function */  int nArg,                 /* Number of arguments.  -1 means any number */  void (*xFunc)(sqlite_func*,int,const char**),  /* C code to implement */  void *pUserData           /* Available via the sqlite_user_data() call */);int sqlite_create_aggregate(  sqlite*,                  /* Database where the new function is registered */  const char *zName,        /* Name of the function */  int nArg,                 /* Number of arguments */  void (*xStep)(sqlite_func*,int,const char**), /* Called for each row */  void (*xFinalize)(sqlite_func*),       /* Called once to get final result */  void *pUserData           /* Available via the sqlite_user_data() call */);/*** Use the following routine to define the datatype returned by a** user-defined function.  The second argument can be one of the** constants SQLITE_NUMERIC, SQLITE_TEXT, or SQLITE_ARGS or it** can be an integer greater than or equal to zero.  When the datatype** parameter is non-negative, the type of the result will be the** same as the datatype-th argument.  If datatype==SQLITE_NUMERIC** then the result is always numeric.  If datatype==SQLITE_TEXT then** the result is always text.  If datatype==SQLITE_ARGS then the result** is numeric if any argument is numeric and is text otherwise.*/int sqlite_function_type(  sqlite *db,               /* The database there the function is registered */  const char *zName,        /* Name of the function */  int datatype              /* The datatype for this function */);#define SQLITE_NUMERIC     (-1)/* #define SQLITE_TEXT     (-2)  // See below */#define SQLITE_ARGS        (-3)/*** SQLite version 3 defines SQLITE_TEXT differently.  To allow both** version 2 and version 3 to be included, undefine them both if a** conflict is seen.  Define SQLITE2_TEXT to be the version 2 value.*/#ifdef SQLITE_TEXT# undef SQLITE_TEXT#else# define SQLITE_TEXT     (-2)#endif#define SQLITE2_TEXT     (-2)/*** The user function implementations call one of the following four routines** in order to return their results.  The first parameter to each of these** routines is a copy of the first argument to xFunc() or xFinialize().** The second parameter to these routines is the result to be returned.** A NULL can be passed as the second parameter to sqlite_set_result_string()** in order to return a NULL result.**** The 3rd argument to _string and _error is the number of characters to** take from the string.  If this argument is negative, then all characters** up to and including the first '\000' are used.**** The sqlite_set_result_string() function allocates a buffer to hold the** result and returns a pointer to this buffer.  The calling routine** (that is, the implmentation of a user function) can alter the content** of this buffer if desired.*/char *sqlite_set_result_string(sqlite_func*,const char*,int);void sqlite_set_result_int(sqlite_func*,int);void sqlite_set_result_double(sqlite_func*,double);void sqlite_set_result_error(sqlite_func*,const char*,int);/*** The pUserData parameter to the sqlite_create_function() and** sqlite_create_aggregate() routines used to register user functions** is available to the implementation of the function using this** call.*/void *sqlite_user_data(sqlite_func*);/*** Aggregate functions use the following routine to allocate** a structure for storing their state.  The first time this routine** is called for a particular aggregate, a new structure of size nBytes** is allocated, zeroed, and returned.  On subsequent calls (for the** same aggregate instance) the same buffer is returned.  The implementation** of the aggregate can use the returned buffer to accumulate data.**** The buffer allocated is freed automatically be SQLite.*/void *sqlite_aggregate_context(sqlite_func*, int nBytes);/*** The next routine returns the number of calls to xStep for a particular** aggregate function instance.  The current call to xStep counts so this** routine always returns at least 1.*/int sqlite_aggregate_count(sqlite_func*);/*** This routine registers a callback with the SQLite library.  The** callback is invoked (at compile-time, not at run-time) for each** attempt to access a column of a table in the database.  The callback** returns SQLITE_OK if access is allowed, SQLITE_DENY if the entire** SQL statement should be aborted with an error and SQLITE_IGNORE** if the column should be treated as a NULL value.*/int sqlite_set_authorizer(  sqlite*,  int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),  void *pUserData);/*** The second parameter to the access authorization function above will** be one of the values below.  These values signify what kind of operation** is to be authorized.  The 3rd and 4th parameters to the authorization** function will be parameters or NULL depending on which of the following** codes is used as the second parameter.  The 5th parameter is the name** of the database ("main", "temp", etc.) if applicable.  The 6th parameter** is the name of the inner-most trigger or view that is responsible for** the access attempt or NULL if this access attempt is directly from ** input SQL code.****                                          Arg-3           Arg-4*/#define SQLITE_COPY                  0   /* Table Name      File Name       */#define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */#define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */#define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */#define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */#define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */#define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */#define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */#define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */#define SQLITE_DELETE                9   /* Table Name      NULL            */#define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */#define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */#define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */#define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -