My code is pretty straight forward.. it simply opens the database and tries to
see if a table exists? m_bdbIsOpen and m_bInMemory are both false (so the db
is opened okay). You'll notice I don't get an error at sqlite3_exec() in the
open method...
bool CDatabase::doesTableExist (const String& tableName, bool& bError)
{
bError = false;
if (! open())
return false;
////////////////////////////////////
sqlite3_stmt* stmt = nullptr;
const char* tail = nullptr;
String szSQL ("pragma table_info('" + tableName + "');");
// Logger::writeToLog ("sql = " + szSQL);
int rc = sqlite3_prepare_v2 (m_db, szSQL.getCharPointer(), -1, &stmt,
&tail);
if (rc != SQLITE_OK)
{
Logger::writeToLog ("CDatabase::doesTableExist() - Error at LINE: " +
String(__LINE__));
showError (rc, stmt);
bError = true;
return false;
}
rc = sqlite3_step (stmt);
int nrows = sqlite3_data_count (stmt);
sqlite3_finalize (stmt);
close();
return nrows > 0;
}
bool CDatabase::open (int iFlags /* = SQLITE_OPEN_READONLY */)
{
const ScopedLock sl (m_Lock);
if ((! m_bDoesExist) && (iFlags & SQLITE_OPEN_READONLY))
{
Logger::writeToLog ("The database doesn't exist!");
return false;
}
if (m_bdbIsOpen)
return true;
m_iFlags = iFlags;
int rc;
if (m_bInMemory)
{
String szInMemory (":memory:");
rc = sqlite3_open_v2 (szInMemory.getCharPointer(), &m_db, iFlags, NULL);
if (rc != SQLITE_OK)
{
showError (rc);
return false;
}
}
else
{
rc = sqlite3_open_v2 (m_szDatabasePath.getCharPointer(), &m_db, iFlags,
NULL);
if (rc != SQLITE_OK)
{
showError (rc);
return false;
}
}
m_bdbIsOpen = true;
++m_iOpenCount;
char *szErr = nullptr;
rc = sqlite3_exec (m_db, "PRAGMA foreign_keys = ON;", NULL, NULL, &szErr);
if (rc != SQLITE_OK)
{
if (szErr != NULL)
{
Logger::writeToLog ("SQL ERROR: " + String (szErr));
return false;
}
}
return true;
}
The 3rd party are trying to imply it's my code at fault -- but I can't see
anything I'm doing wrong.
> I consider this a bug but have been told that there's no appropriate way to
> fix it until SQLite4 comes along.
So you're saying I'm basically screwed :)
Thanks,
Rail
-------------------------------------------------
On Apr 5, 2016, at 7:10 PM, Simon Slavin <slavins at bigfraud.org> wrote:
>
> On 6 Apr 2016, at 2:59am, Rail Jon Rogut <sqlite3 at platinumsamples.com>
> wrote:
>
>> Oh -- and the database opens fine -- it only fails when I try and call
>> sqlite3_prepare_v2() to check if a table exists in the database
>
> The sqlite3_open() routines don't actually do any file access at all (most of
> the time). They just set up some structures in memory. The file is actually
> opened by the first SQLite call which needs to read or write them. So that's
> when you get the access errors.
>
> I consider this a bug but have been told that there's no appropriate way to
> fix it until SQLite4 comes along.
>
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users