Skip to content

Commit aae8c3d

Browse files
committed
Properly escape table names
The method CppSQLite3DB::tableExist was not escaping the table names in the sql query properly, which caused exceptions when the table name contains quotes. The fix was simply to change the string formatting to use the sqlite specific printf variant (through CppSQLite3Buffer) with a %Q. This has the nice side effect of also removing a warning when building with visual studio.
1 parent b2651c2 commit aae8c3d

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

CppSQLite3.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,11 +1166,10 @@ CppSQLite3Statement CppSQLite3DB::compileStatement(const char* szSQL)
11661166

11671167
bool CppSQLite3DB::tableExists(const char* szTable)
11681168
{
1169-
char szSQL[128];
1170-
sprintf(szSQL,
1171-
"select count(*) from sqlite_master where type='table' and name='%s'",
1172-
szTable);
1173-
int nRet = execScalar(szSQL);
1169+
CppSQLite3Buffer sql;
1170+
sql.format( "select count(*) from sqlite_master where type='table' and name=%Q",
1171+
szTable );
1172+
int nRet = execScalar(sql);
11741173
return (nRet > 0);
11751174
}
11761175

0 commit comments

Comments
 (0)