I'm trying to update some code I have to use Binding Instead of native Queries.
I'm using the the ETL model to load this data.
It all starts with me creating a table with all columns defined as Text.
Create Table TableA ( Col1 Text, Col2 Text);
I then populate the table using native queries like,
INSERT INTO TABLEA ('A', '2');
INSERT INTO TABLEA ('B', 'Bad_VALUE_Not_INT');
I then create a real data table
Create Table RealTableA ( Col1 Text, Col2 Integer);
And then insert the values into the real table and Delete ones with the wrong datatype as explained here
INSERT INTO RealTableA SELECT * FROM TABLEA;
DELETE FROM RealTableA WHERE typeof(col2) != 'integer'
This works great when I wrote the queries and submitted them natively. But I now want to Bind Variables to a statement instead of using Native Queries as explained here
So I changed the code to use sqlite3_bind_text
with a prepared_statement.
Now SQLite thinks every value in col2
is really 'text'
when I query using typeof(col2)
this is erasing EVERYTHING.
I find this strange because of the example of type affinity SQLite has here.
How do I fix this without rewriting all my ETL queries after the initial load?
I found a binding function called sqlite3_bind_value
who's definition sounds like it will treat the values bound to it as numeric
which is what I want. The problem is it takes a SQLite3_value*
and I can't for the life of me figure out how to make text values from a file into that.
Ideas? Am I way off with this approach?
Also why is it when I bind values they get a hard 'TEXT' type designation but when I insert into a 'TEXT' column it allows some wiggle room for other types?
Note: I'm using the C/C++ interface with Visual Studios 2010 and I'm on version 3.7.13 of SQLite.