[wxsqlite3] Suggestion to remove sprintf in TableExists()

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Jamie
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

[wxsqlite3] Suggestion to remove sprintf in TableExists()

Post by Jamie »

Hi,

Looking at CVS I noticed you fixed the non-POD bug in TableExists. Perhaps you could change the function to this:

Code: Select all

bool wxSQLite3Database::TableExists(const wxString& tableName)
{
  wxString sql;
  sql << _T("select count(*) from sqlite_master where type='table' and name='") << tableName << _T("'");
  int rc = ExecuteScalar(sql);
  return (rc > 0);
}
Since sqlite can have table names longer than what you allow for by using sprintf with a buffer of 128 bytes. (If you must use sprintf then use snprintf).

Also, gcc complains:

wxsqlite3.h:280: warning:
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: [wxsqlite3] Suggestion to remove sprintf in TableExists(

Post by utelle »

Jamie wrote:Looking at CVS I noticed you fixed the non-POD bug in TableExists. Perhaps you could change the function to this:

Code: Select all

bool wxSQLite3Database::TableExists(const wxString& tableName)
{
  wxString sql;
  sql << _T("select count(*) from sqlite_master where type='table' and name='") << tableName << _T("'");
  int rc = ExecuteScalar(sql);
  return (rc > 0);
}
Good idea! I changed the code in CVS accordingly. Thanks!
Jamie wrote:Also, gcc complains:

wxsqlite3.h:280: warning:
Jamie
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Post by Jamie »

Thank you for the great work!
Post Reply