Exemplo n.º 1
0
/*
** Trigger the alarm
*/
static void sqlite3MemsysAlarm(int nByte) {
    void (*xCallback)(void*,sqlite3_int64,int);
    sqlite3_int64 nowUsed;
    void *pArg;
    if( mem.alarmCallback==0 || mem.alarmBusy  ) return;
    mem.alarmBusy = 1;
    xCallback = mem.alarmCallback;
    nowUsed = mem.nowUsed;
    pArg = mem.alarmArg;
    sqlite3_mutex_leave(mem.mutex);
    xCallback(pArg, nowUsed, nByte);
    sqlite3_mutex_enter(mem.mutex);
    mem.alarmBusy = 0;
}
Exemplo n.º 2
0
/*
** Trigger the alarm 
*/
static void sqlite3MallocAlarm(int nByte){
  void (*xCallback)(void*,sqlite3_int64,int);
  sqlite3_int64 nowUsed;
  void *pArg;
  if( mem0.alarmCallback==0 || mem0.alarmBusy  ) return;
  mem0.alarmBusy = 1;
  xCallback = mem0.alarmCallback;
  nowUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
  pArg = mem0.alarmArg;
  sqlite3_mutex_leave(mem0.mutex);
  xCallback(pArg, nowUsed, nByte);
  sqlite3_mutex_enter(mem0.mutex);
  mem0.alarmBusy = 0;
}
Exemplo n.º 3
0
/*
** Trigger the alarm 
*/
static void systemMallocAlarm(int nByte)
{
	void (*xCallback)(void*,i64,int);
	i64 nowUsed;
	void *pArg;
	if( mem0.alarmCallback==0 ) return;
	xCallback = mem0.alarmCallback;
	nowUsed = systemStatusValue(SYSTEM_MEMSTATUS_MEMORY_USED);
	pArg = mem0.alarmArg;
	mem0.alarmCallback = 0;
	system_mutex_leave(mem0.mutex);
	xCallback(pArg, nowUsed, nByte);
	system_mutex_enter(mem0.mutex);
	mem0.alarmCallback = xCallback;
	mem0.alarmArg = pArg;
}
Exemplo n.º 4
0
int sqlite3FaultSim(int iTest){
  int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
  return xCallback ? xCallback(iTest) : SQLITE_OK;
}
Exemplo n.º 5
0
/*
** Execute a statement or set of statements.  Print 
** any result rows/columns depending on the current mode 
** set via the supplied callback.
**
** This is very similar to SQLite's built-in sqlite3_exec() 
** function except it takes a slightly different callback 
** and callback data argument.
*/
static int shell_exec(
					  sqlite3 *db,                                /* An open database */
					  const char *zSql,                           /* SQL to be evaluated */
					  int (*xCallback)(void*,int,char**,char**,int*),   /* Callback function (not the same as sqlite3_exec) */
					  struct callback_data *pArg,                 /* Pointer to struct callback_data */
					  char **pzErrMsg                             /* Error msg written here */
	)
{
	sqlite3_stmt *pStmt = NULL;     /* Statement to execute. */
	int rc = SQLITE_OK;             /* Return Code */
	const char *zLeftover;          /* Tail of unprocessed SQL */

	if( pzErrMsg ){
		*pzErrMsg = NULL;
	}

	while( zSql[0] && (SQLITE_OK == rc) ){
		rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
		if( SQLITE_OK != rc ){
			if( pzErrMsg ){
				*pzErrMsg = save_err_msg(db);
			}
		}else{
			if( !pStmt ){
				/* this happens for a comment or white-space */
				zSql = zLeftover;
				while( isspace(zSql[0]) ) zSql++;
				continue;
			}

			/* save off the prepared statment handle and reset row count */
			if( pArg ){
				pArg->pStmt = pStmt;
				pArg->cnt = 0;
			}

			/* perform the first step.  this will tell us if we
			** have a result set or not and how wide it is.
			*/
			rc = sqlite3_step(pStmt);
			/* if we have a result set... */
			if( SQLITE_ROW == rc ){
				/* if we have a callback... */
				if( xCallback ){
					/* allocate space for col name ptr, value ptr, and type */
					int nCol = sqlite3_column_count(pStmt);
					void *pData = sqlite3_malloc(3*nCol*sizeof(const char*) + 1);
					if( !pData ){
						rc = SQLITE_NOMEM;
					}else{
						char **azCols = (char **)pData;      /* Names of result columns */
						char **azVals = &azCols[nCol];       /* Results */
						int *aiTypes = (int *)&azVals[nCol]; /* Result types */
						int i;
						assert(sizeof(int) <= sizeof(char *)); 
						/* save off ptrs to column names */
						for(i=0; i<nCol; i++){
							azCols[i] = (char *)sqlite3_column_name(pStmt, i);
						}
						do{
							/* extract the data and data types */
							for(i=0; i<nCol; i++){
								azVals[i] = (char *)sqlite3_column_text(pStmt, i);
								aiTypes[i] = sqlite3_column_type(pStmt, i);
								if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
									rc = SQLITE_NOMEM;
									break; /* from for */
								}
							} /* end for */

							/* if data and types extracted successfully... */
							if( SQLITE_ROW == rc ){ 
								/* call the supplied callback with the result row data */
								if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
									rc = SQLITE_ABORT;
								}else{
									rc = sqlite3_step(pStmt);
								}
							}
						} while( SQLITE_ROW == rc );
						sqlite3_free(pData);
					}
				}else{
					do{
						rc = sqlite3_step(pStmt);
					} while( rc == SQLITE_ROW );
				}
			}

			/* Finalize the statement just executed. If this fails, save a 
			** copy of the error message. Otherwise, set zSql to point to the
			** next statement to execute. */
			rc = sqlite3_finalize(pStmt);
			if( rc==SQLITE_OK ){
				zSql = zLeftover;
				while( isspace(zSql[0]) ) zSql++;
			}else if( pzErrMsg ){
				*pzErrMsg = save_err_msg(db);
			}

			/* clear saved stmt handle */
			if( pArg ){
				pArg->pStmt = NULL;
			}
		}
	} /* end while */

	return rc;
}