Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob type returned ? #59

Closed
lexicalunit opened this issue Oct 14, 2017 · 4 comments
Closed

Blob type returned ? #59

lexicalunit opened this issue Oct 14, 2017 · 4 comments

Comments

@lexicalunit
Copy link
Contributor

From @renzo38 on December 8, 2014 11:48

Hello,

First of all, thanks for this really great wrapper. I am encountering a problem while using nanodbc on the following platform:

  • Fedora Core 20
  • sqlite-3.8.7
  • sqliteodbc-0.999
  • unixODBC-2.3.2-4
  • latest nanodbc release

I open a minimalist sqlite db containing only one table created as follow:

CREATE TABLE "PIPES" ("Name" TEXT);

Then, trying to execute the request:

SELECT name FROM sqlite_master WHERE type='table';

leads to a runtime_error with "blob not implemented yet" as the error message. Is this a bug or not ?

Thanks.

Copied from original issue: lexicalunit/nanodbc#32

@lexicalunit
Copy link
Contributor Author

I never implemented proper handling of the BLOB types because it was never necessary for my purposes. It looks like in this case the sqlite_master.name column is being detected as a long varchar datatype, which is processed as a BLOB type. That's why you get the runtime_error indicating that it's not implemented. There's a workaround here using CAST to avoid using BLOB types:

#include <iostream>
#include <string>
#include "nanodbc.h"

using namespace std;
using namespace nanodbc;

int main()
{
    connection c("Driver=sqlite;Database=this_test.db;");
    execute(c, "CREATE TABLE IF NOT EXISTS PIPES (Name TEXT);");
    result r = execute(c, "SELECT CAST(name AS text) FROM sqlite_master WHERE type = 'table';");
    r.next();
    cout << r.get<string>(0) << endl;
}

/*

$ c++ -Wall -Werror -I/usr/local/include -L/usr/local/lib -lodbc nanodbc.cpp this_test.cpp
$ ./a.out # PIPES

*/

Let me know if that also works for you on Fedora Core. I ran the above test on an OS X machine.

@lexicalunit
Copy link
Contributor Author

lexicalunit commented Oct 14, 2017

From @renzo38 on December 9, 2014 7:58

Thanks for your answer, I try it on my FC20 but it crashes like my sample
code (I joined the backtrace below). I tested the same code on a RHEL6.4,
first the runtime_exception is launched without the CAST, and then it works
with this keyword. So, I think sqlite or unixODBC package is the problem.
The differences are as follow ( RHEL6.4 / FC20 ):

  • sqlite-3.6.20 / sqlite-3.8.7.2
  • unixODBC-2.2.14 / unixODBC-2.3.2-4
  • sqliteodbc is the same

Regards.

###Stack trace under gdb

#0  0x00000035fe40f677 in sqlite3_stricmp (zLeft=0x64fff8
"sqlite_temp_master", zRight=zRight@entry=0x0) at sqlite3.c:23047
#1  0x00000035fe4105f5 in findElementWithHash (pH=<optimized out>,
pKey=pKey@entry=0x0, pHash=pHash@entry=0x7fffffffd794) at sqlite3.c:24322
#2  0x00000035fe411e3d in sqlite3HashFind (pKey=0x0, pH=<optimized out>) at
sqlite3.c:24374
#3  sqlite3FindTable (db=db@entry=0x63ae18, zName=zName@entry=0x0,
zDatabase=zDatabase@entry=0x0) at sqlite3.c:23341
#4  0x00000035fe47bdf8 in sqlite3_table_column_metadata (db=0x63ae18,
zDbName=zDbName@entry=0x0, zTableName=zTableName@entry=0x0,
zColumnName=0x0,
    pzDataType=pzDataType@entry=0x7fffffffd8c8,
pzCollSeq=pzCollSeq@entry=0x7fffffffd8d0,
pNotNull=pNotNull@entry=0x7fffffffd8bc, pPrimaryKey=pPrimaryKey@entry
=0x7fffffffd8c0,
    pAutoinc=pAutoinc@entry=0x7fffffffd8c4) at sqlite3.c:127909
#5  0x00007ffff7898266 in s3stmt_addmeta (s3stmt=s3stmt@entry=0x64ec48,
col=col@entry=0, ci=0x64e658, ci=0x64e658, d=0x639668, d=0x639668) at
sqlite3odbc.c:4004
#6  0x00007ffff7898a3c in setupdyncols (s=s@entry=0x64f9e8,
s3stmt=0x64ec48, ncolsp=ncolsp@entry=0x7fffffffda04) at sqlite3odbc.c:16597
#7  0x00007ffff78997e5 in drvprepare (stmt=stmt@entry=0x64f9e8,
query=<optimized out>, queryLen=<optimized out>) at sqlite3odbc.c:16705
#8  0x00007ffff78ab969 in SQLExecDirect (stmt=0x64f9e8, query=<optimized
out>, queryLen=<optimized out>) at sqlite3odbc.c:17073
#9  0x0000003074816262 in SQLExecDirect (statement_handle=0x64f350,
statement_text=0x64e768 "SELECT CAST(name AS text) FROM sqlite_master WHERE
type = 'table';", text_length=-3)
    at SQLExecDirect.c:421
#10 0x00000000004087ae in
nanodbc::statement::statement_impl::execute_direct (this=0x64e5f0,
conn=..., query="SELECT CAST(name AS text) FROM sqlite_master WHERE type =
'table';",
    batch_operations=1, timeout=0, statement=...) at nanodbc.cpp:1079
#11 0x0000000000404b61 in nanodbc::statement::execute_direct
(this=0x7fffffffdcb0, conn=..., query="SELECT CAST(name AS text) FROM
sqlite_master WHERE type = 'table';",
    batch_operations=1, timeout=0) at nanodbc.cpp:2545
#12 0x000000000040405d in nanodbc::execute (conn=..., query="SELECT
CAST(name AS text) FROM sqlite_master WHERE type = 'table';",
batch_operations=1, timeout=0)
    at nanodbc.cpp:2227
#13 0x0000000000402cde in main () at tst_nanodbc.cpp:16

@lexicalunit
Copy link
Contributor Author

From @renzo38 on March 17, 2015 12:50

The unixODBC and sqlite RPM packages have been updated on Fedora Core 21 as follow:

  • unixODBC-2.3.2-6
  • sqlite-3.8.8.3-1

The CAST now works on this platform, this issue can be closed.

Thx

@lexicalunit
Copy link
Contributor Author

Much thanks for the update!

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

No branches or pull requests

1 participant