A running, memory fly old fast, support a move for the great god, can't play,
A rookie, you great god to explain in detail, very thank you!!!!!
Extern "C" int PASCAL EXPORT readb (int nRow [], int nColumn [], would be * sysbol)
{
AFX_MANAGE_STATE (AfxGetStaticModuleState ());
Sqlite3 * db=NULL;//declare the sqlite key structure pointer
Int result;//receive open file returns the success variables
Char * * dbResult=NULL;
Int my_age=0;
Char * * errmsg=NULL;//executing SQL statements error message receiving variables
Result=sqlite3_open (" c: \ \ Windows. Db ", & amp; Db);//open the sqlite3 database file, if the file does not exist, will create the sqlite3 database file
If (result!=SQLITE_OK)//whether the database open or create a successful, if successful result==0
{
Sqlite3_free (errmsg);
Sqlite3_close (db);
return NULL;
}
Int pSize1=WideCharToMultiByte (CP_OEMCP, 0, sysbol, wcslen (sysbol), NULL, 0, NULL, NULL);
If (pSize1==0)
{
return NULL;
}
Char * pC1=new char [pSize1 + 1];
WideCharToMultiByte (CP_OEMCP, 0, sysbol, wcslen (sysbol), pC1, pSize1, NULL, NULL);
PC1 [pSize1]='\ 0';
Char buffer [1024].
Sprintf (buffer, "select * from % s", pC1);
Result=sqlite3_get_table (db, buffer, & amp; DbResult, nRow, nColumn, errmsg);
If (result!=SQLITE_OK)//whether the database open or create a successful, if successful result==0
{
The delete [] pC1;
PC1=NULL;
Sqlite3_free (errmsg);
return NULL;
}
The delete [] pC1;
PC1=NULL;
Int index=0;
For (int I=0; i <(nRow [0] + 1) * nColumn [0]. I++)
{
The index=I - 1;
}
//char * t=dbResult [index];
My_age=atoi (dbResult [index]);
Sqlite3_free_table (dbResult);
Sqlite3_close (db);
Return my_age;
}
CodePudding user response:
Don't see the memory leak place ah, see sysbol variable is how to deal with
CodePudding user response: