DatabaseColumnType issue

Just starting out? Need help? Post your questions and find answers here.
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

DatabaseColumnType issue

Post by Jordi »

I'm using SQLITE engine of PB.

If I send a request with this query:

Code: Select all

SELECT date FROM table
DatabaseColumnType returns for the first column (0) after DatabaseQuery: 2, this is right because "date" field is a date as its name means.

But with this query:

Code: Select all

SELECT MIN(date) FROM table
DatabaseColumnType returns for the first column (0) after DatabaseQuery: 0, and 0 is an unknown type for PB.

Anyone can help me? I suppose this has a reason, but I have not found it looking in the forum, pb help, sql help.

Thanks!
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

This might help

http://www.sqlite.org/datatype3.html
http://www.sqlite.org/lang_createtable.html

Many types are "supported" but don't exist in actuality, VARCHAR is just TEXT renamed for support reasons. You can query the table itself and see what SQL created it, the type might be just TEXT as there is no dedicated DATE type.

maybe something like that is tripping the PB proc up
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post by Jordi »

Thanks pdwyer.

Yes, GetDatabaseString runs ok and I can get the date, but the problem is when type of column is not defined on compiling time, when you don't know the query, when query is definied on runtime.

Any idea how get the type easily? Thks.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

A PB person should probably answer, I think this needs to have a bit of extra logic added for sqllite to get the underlying type
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post by Jordi »

Thanks Paul.

I hope there is a solution for this issue because I have only one idea to solve this myself, it is parsing the query instance... too much hard for me.
User avatar
the.weavster
Addict
Addict
Posts: 1577
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Post by the.weavster »

Even if you call select * from sqlite_master where type = 'table' and parse the response you wont necessarily get the answer because declaring a datatype in a create table... statement is optional with SQLite.
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post by Jordi »

Perhaps a "tricky" way to solve by the moment the issue:

Code: Select all

SELECT MIN(date), typeof(MIN(date)) FROM table
With the above code the second column has the type of the first so I have to parse the columns queried between SELECT and FROM and add the same number of columns for type or save the original query to do a previous query getting the types of columns involved in the query, adding typeof() to any field between select and from.

Any better idea?
Post Reply