Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Question about max query lenght #2

Closed
KhArtNJava opened this issue Jun 29, 2015 · 2 comments
Closed

Question about max query lenght #2

KhArtNJava opened this issue Jun 29, 2015 · 2 comments

Comments

@KhArtNJava
Copy link
Contributor

Hi.

I found, that max possible query length for sqlite3_exec may be 127 symbols.
For example:

code:

ANSICHAR* dbNameAsUtf8 = TCHAR_TO_UTF8(*Databases[DatabaseName]);
    int32 i = sqlite3_open(dbNameAsUtf8, &db);

    if (i == SQLITE_OK){

        ANSICHAR* queryAsUtf8 = TCHAR_TO_UTF8(*query);
        int32 k = sqlite3_exec(db, queryAsUtf8, NULL, 0, &zErrMsg);

        if (i == SQLITE_OK){
            success = true;
        }
        else {
            LOGSQLITE(Warning, TEXT("CreateTable - Query Exec Failed.."));
        }

Query with string length 127 worked well:

CREATE TABLE IF NOT EXISTS dsfsdfdfDFDFDFADSFADSFASFSDFSAFASFASFASDFSADFSDFSD777(F1 INTEGER , F2 TEXT , F3 REAL , f4 NUMERIC );

But same query, but with 128 symbols

CREATE TABLE IF NOT EXISTS dsfsdfdfDFDFDFADSFADSFASFSDFSAFASFASFASDFSADFSDFSD777A(F1 INTEGER , F2 TEXT , F3 REAL , f4 NUMERIC );

Executes without error, but table not created.

Can you explain, how to fix this (possible bug)?

@KhArtNJava
Copy link
Contributor Author

... And I found, that if I run

int32 k = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS dsfsdfdfDFDFDFADSFADSFASFSDFSAFASFASFASDFSADFSDFSD777A(F1 INTEGER , F2 TEXT , F3 REAL , f4 NUMERIC );", NULL, 0, &zErrMsg);
  • it's works well - table created.
    May be it's issue of the
ANSICHAR* queryAsUtf8 = TCHAR_TO_UTF8(*query);

May be ANSICHAR* queryAsUtf8 max len is 127 bytes?

@KhArtNJava
Copy link
Contributor Author

Fixed by removing

ANSICHAR* queryAsUtf8 = TCHAR_TO_UTF8(*query);

Now code works good and looks like:

int32 k = sqlite3_exec(db, TCHAR_TO_UTF8(*query), NULL, 0, &zErrMsg);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant