08-04-2009 04:21 AM - edited 08-04-2009 04:25 AM
Hi
I downloaded the latest sqlite file and currently trying to use sqlite3 but every time i try to add a table i get an error
" "sqlite3.c", line 70193, col 30, thread id 0x00000F50: Pointer arithmetic involving null pointer." in sqlite3_prepare_v2() function.
This is my current coding :
int main()
{
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
sqlite3_initialize();
sqlite3_open("test.db", &DB);
Str=CreateTable("Info");//Creates SQL Query and is correct
StepQuery(Str); //View Below
sqlite3_close(DB);
}
//----------------------------------------------------------------//
void StepQuery(char *query)
{
const char *query_tail=NULL;
int MaxQueryLength=499;
sqlite3_stmt *stmt=NULL;
int i,result,numCols=0;
const char **results=NULL;
const char **columnNames=NULL;
const unsigned char* Columntext;
/* We skip the other variable declarations and the code to open the database */
//execute query
result=sqlite3_prepare_v2(DB, query, MaxQueryLength, &stmt, &query_tail);//This in this function is the where im receiving the errordo {
result=sqlite3_step(stmt);//if null pointer error skipped crashes over hereif (result==SQLITE_ROW){
for (i=0; i<numCols; i++){
/* Do something with this field in the results; I guess we'll print it.*/
Columntext=sqlite3_column_text(stmt, i);
}
printf("\n");
}
} while (result==SQLITE_ROW);
sqlite3_finalize(stmt);
}
Can some body please help me understand why this is happening ?
Solved! Go to Solution.
08-04-2009 08:10 AM
Are you getting this message when trying to run a debug build? If so then there might be an issue with the const qualifier on the passed parameters into the function - these have been known to cause problems with the CVI debug framework code in the past. Try removing the qualfier from the definitions and see if you still get the error.
JR
08-04-2009 08:20 AM
I have sovled the problem.
Here is where the problem was and how i sovled it :
#if defined(__GNUC__) # if defined(HAVE_STDINT_H) # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) # else # define SQLITE_INT_TO_PTR(X) ((void*)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(X)) # endif #else # define SQLITE_INT_TO_PTR(X) ((void*)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(X)) //# define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) //# define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) #endif
08-04-2009 08:22 AM
Thanks for the input.
I have sovled the problem.
Here is where the problem was and how i sovled it :
#if defined(__GNUC__) # if defined(HAVE_STDINT_H) # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) # else # define SQLITE_INT_TO_PTR(X) ((void*)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(X)) # endif #else # define SQLITE_INT_TO_PTR(X) ((void*)(X)) # define SQLITE_PTR_TO_INT(X) ((int)(X)) //# define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) //# define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) #endif