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

📄 test1.c

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 C
📖 第 1 页 / 共 5 页
字号:
  char **argv            /* Text of each argument */){  char zBuf[200];  sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail);  Tcl_AppendResult(interp, zBuf, 0);  return TCL_OK;}/*** This function implements a Tcl command that may be invoked using any of** the four forms enumerated below.**** sqlite_malloc_outstanding**     Return a summary of all unfreed blocks of memory allocated by the**     current thread. See comments above function sqlite3OutstandingMallocs() **     in util.c for a description of the returned value.**** sqlite_malloc_outstanding -bytes**     Return the total amount of unfreed memory (in bytes) allocated by **     this thread.**** sqlite_malloc_outstanding -maxbytes**     Return the maximum amount of dynamic memory in use at one time **     by this thread.**** sqlite_malloc_outstanding -clearmaxbytes**     Set the value returned by [sqlite_malloc_outstanding -maxbytes]**     to the current value of [sqlite_malloc_outstanding -bytes]. */static int sqlite_malloc_outstanding(  ClientData clientData,  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);#if defined(SQLITE_DEBUG) && defined(SQLITE_MEMDEBUG) && SQLITE_MEMDEBUG>1  if( objc==2 ){    const char *zArg = Tcl_GetString(objv[1]);#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT    ThreadData const *pTd = sqlite3ThreadDataReadOnly();    if( 0==strcmp(zArg, "-bytes") ){      Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc));    }else if( 0==strcmp(zArg, "-clearmaxbytes") ){      sqlite3_nMaxAlloc = pTd->nAlloc;    }else #endif    if( 0==strcmp(zArg, "-maxbytes") ){      Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3_nMaxAlloc));    }else{      Tcl_AppendResult(interp, "bad option \"", zArg,         "\": must be -bytes, -maxbytes or -clearmaxbytes", 0      );      return TCL_ERROR;    }    return TCL_OK;  }  if( objc!=1 ){    Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?");    return TCL_ERROR;  }  return sqlite3OutstandingMallocs(interp);#else  return TCL_OK;#endif}#endif/*** Usage: sqlite3_enable_shared_cache      BOOLEAN***/#if !defined(SQLITE_OMIT_SHARED_CACHE)static int test_enable_shared(  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  int rc;  int enable;  int ret = 0;  if( objc!=2 ){    Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");    return TCL_ERROR;  }  if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){    return TCL_ERROR;  }  ret = sqlite3ThreadDataReadOnly()->useSharedData;  rc = sqlite3_enable_shared_cache(enable);  if( rc!=SQLITE_OK ){    Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC);    return TCL_ERROR;  }  Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret));  return TCL_OK;}#endif/*** Usage: sqlite3_extended_result_codes   DB    BOOLEAN***/static int test_extended_result_codes(  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  int enable;  sqlite3 *db;  if( objc!=3 ){    Tcl_WrongNumArgs(interp, 1, objv, "DB BOOLEAN");    return TCL_ERROR;  }  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;  if( Tcl_GetBooleanFromObj(interp, objv[2], &enable) ) return TCL_ERROR;  sqlite3_extended_result_codes(db, enable);  return TCL_OK;}/*** Usage: sqlite3_libversion_number***/static int test_libversion_number(  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number()));  return TCL_OK;}/*** Usage: sqlite3_table_column_metadata DB dbname tblname colname***/#ifdef SQLITE_ENABLE_COLUMN_METADATAstatic int test_table_column_metadata(  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  sqlite3 *db;  const char *zDb;  const char *zTbl;  const char *zCol;  int rc;  Tcl_Obj *pRet;  const char *zDatatype;  const char *zCollseq;  int notnull;  int primarykey;  int autoincrement;  if( objc!=5 ){    Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname");    return TCL_ERROR;  }  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;  zDb = Tcl_GetString(objv[2]);  zTbl = Tcl_GetString(objv[3]);  zCol = Tcl_GetString(objv[4]);  if( strlen(zDb)==0 ) zDb = 0;  rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol,       &zDatatype, &zCollseq, &notnull, &primarykey, &autoincrement);  if( rc!=SQLITE_OK ){    Tcl_AppendResult(interp, sqlite3_errmsg(db), 0);    return TCL_ERROR;  }  pRet = Tcl_NewObj();  Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1));  Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1));  Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull));  Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey));  Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement));  Tcl_SetObjResult(interp, pRet);  return TCL_OK;}#endif#ifndef SQLITE_OMIT_INCRBLOB/*** sqlite3_blob_read  CHANNEL OFFSET N****   This command is used to test the sqlite3_blob_read() in ways that**   the Tcl channel interface does not. The first argument should**   be the name of a valid channel created by the [incrblob] method**   of a database handle. This function calls sqlite3_blob_read()**   to read N bytes from offset OFFSET from the underlying SQLite**   blob handle.****   On success, a byte-array object containing the read data is **   returned. On failure, the interpreter result is set to the**   text representation of the returned error code (i.e. "SQLITE_NOMEM")**   and a Tcl exception is thrown.*/static int test_blob_read(  ClientData clientData, /* Not used */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  Tcl_Channel channel;  ClientData instanceData;  sqlite3_blob *pBlob;  int notUsed;  int nByte;  int iOffset;  unsigned char *zBuf;  int rc;    if( objc!=4 ){    Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET N");    return TCL_ERROR;  }  channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), &notUsed);  if( !channel   || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset)   || TCL_OK!=Tcl_GetIntFromObj(interp, objv[3], &nByte)   || nByte<0 || iOffset<0  ){     return TCL_ERROR;  }  instanceData = Tcl_GetChannelInstanceData(channel);  pBlob = *((sqlite3_blob **)instanceData);  zBuf = (unsigned char *)Tcl_Alloc(nByte);  rc = sqlite3_blob_read(pBlob, zBuf, nByte, iOffset);  if( rc==SQLITE_OK ){    Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zBuf, nByte));  }else{    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);  }  Tcl_Free((char *)zBuf);  return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);}/*** sqlite3_blob_write CHANNEL OFFSET DATA****   This command is used to test the sqlite3_blob_write() in ways that**   the Tcl channel interface does not. The first argument should**   be the name of a valid channel created by the [incrblob] method**   of a database handle. This function calls sqlite3_blob_write()**   to write the DATA byte-array to the underlying SQLite blob handle.**   at offset OFFSET.****   On success, an empty string is returned. On failure, the interpreter**   result is set to the text representation of the returned error code **   (i.e. "SQLITE_NOMEM") and a Tcl exception is thrown.*/static int test_blob_write(  ClientData clientData, /* Not used */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  Tcl_Channel channel;  ClientData instanceData;  sqlite3_blob *pBlob;  int notUsed;  int iOffset;  int rc;  unsigned char *zBuf;  int nBuf;    if( objc!=4 ){    Tcl_WrongNumArgs(interp, 1, objv, "CHANNEL OFFSET DATA");    return TCL_ERROR;  }  channel = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), &notUsed);  if( !channel   || TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iOffset)   || iOffset<0  ){     return TCL_ERROR;  }  instanceData = Tcl_GetChannelInstanceData(channel);  pBlob = *((sqlite3_blob **)instanceData);  zBuf = Tcl_GetByteArrayFromObj(objv[3], &nBuf);  rc = sqlite3_blob_write(pBlob, zBuf, nBuf, iOffset);  if( rc!=SQLITE_OK ){    Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);  }  return (rc==SQLITE_OK ? TCL_OK : TCL_ERROR);}#endif/*** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC****   This Tcl proc is used for testing the experimental**   sqlite3_create_collation_v2() interface.*/struct TestCollationX {  Tcl_Interp *interp;  Tcl_Obj *pCmp;  Tcl_Obj *pDel;};typedef struct TestCollationX TestCollationX;static void testCreateCollationDel(void *pCtx){  TestCollationX *p = (TestCollationX *)pCtx;  int rc = Tcl_EvalObjEx(p->interp, p->pDel, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL);  if( rc!=TCL_OK ){    Tcl_BackgroundError(p->interp);  }  Tcl_DecrRefCount(p->pCmp);  Tcl_DecrRefCount(p->pDel);  sqlite3_free((void *)p);}static int testCreateCollationCmp(  void *pCtx,  int nLeft,  const void *zLeft,  int nRight,  const void *zRight){  TestCollationX *p = (TestCollationX *)pCtx;  Tcl_Obj *pScript = Tcl_DuplicateObj(p->pCmp);  int iRes = 0;  Tcl_IncrRefCount(pScript);  Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zLeft, nLeft));  Tcl_ListObjAppendElement(0, pScript, Tcl_NewStringObj((char *)zRight,nRight));  if( TCL_OK!=Tcl_EvalObjEx(p->interp, pScript, TCL_EVAL_DIRECT|TCL_EVAL_GLOBAL)   || TCL_OK!=Tcl_GetIntFromObj(p->interp, Tcl_GetObjResult(p->interp), &iRes)  ){    Tcl_BackgroundError(p->interp);  }  Tcl_DecrRefCount(pScript);  return iRes;}static int test_create_collation_v2(  ClientData clientData, /* Not used */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  TestCollationX *p;  sqlite3 *db;  if( objc!=5 ){    Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE NAME CMP-PROC DEL-PROC");    return TCL_ERROR;  }  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;  p = (TestCollationX *)sqlite3_malloc(sizeof(TestCollationX));  p->pCmp = objv[3];  p->pDel = objv[4];  p->interp = interp;  Tcl_IncrRefCount(p->pCmp);  Tcl_IncrRefCount(p->pDel);  sqlite3_create_collation_v2(db, Tcl_GetString(objv[2]), SQLITE_UTF8,       (void *)p, testCreateCollationCmp, testCreateCollationDel  );  return TCL_OK;}/*** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?*/static int test_load_extension(  ClientData clientData, /* Not used */  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */  int objc,              /* Number of arguments */  Tcl_Obj *CONST objv[]  /* Command arguments */){  Tcl_CmdInfo cmdInfo;  sqlite3 *db;  int rc;  char *zDb;  char *zFile;  char *zProc = 0;  char *zErr = 0;  if( objc!=4 && objc!=3 ){    Tcl_WrongNumArgs(interp, 1, objv, "DB-HANDLE FILE ?PROC?");    return TCL_ERROR;  }  zDb = Tcl_GetString(objv[1]);  zFile = Tcl_GetString(objv[2]);  if( objc==4 ){    zProc = Tcl_GetString(objv[3]);  }  /* Extract the C database handle from the Tcl command name */  if( !Tcl_GetCommandInfo(interp, zDb, &cmdInfo) ){    Tcl_AppendResult(interp, "command not found: ", zDb, (char*)0);    return TCL_ERROR;  }  db = ((struct SqliteDb*)cmdInfo.objClientData)->db;  assert(db);  /* Call the underlying C function. If an error occurs, set rc to   ** TCL_ERROR and load any error string into the interpreter. If no   ** error occurs, set rc to TCL_OK.  */#ifdef SQLITE_OMIT_LOAD_EXTENSION  rc = SQLITE_ERROR;  zErr = sqlite3_mprintf("this build omits sqlite3_load_extension()");#else  rc = sqlite3_load_extension(db, zFile, zProc, &zErr);#endif  if( rc!=SQLITE_OK ){    Tcl_SetResult(interp, zErr ? zErr : "", TCL_VOLATILE);    rc = TCL_ERROR;  }else{    rc = TCL_OK;  }  sqlite3_free(zErr);  return rc;}/*

⌨️ 快捷键说明

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