Categories > TinyButStrong general >

TbsSQL - GetRow question: varchar vs. integer, decimal data types

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: John Lawler
Date: 2012-05-24
Time: 23:06

TbsSQL - GetRow question: varchar vs. integer, decimal data types

Skrol,

Quick question that I didn't find an answer to in the documentation and Google searches.  If I do something like this w/ GetRow:

$data = $Db->GetRow("
   SELECT
     VarCol,
     IntCol
   FROM
     Table
   WHERE
     Key = %1%", $Key);

in TBS (not using any template here, just focusing on your GetRow function), when I examine the array that ends up in $data, I see that the value side of all of the key/value pairs appears to always be a string, even when the column in the database is an integer.

E.g., the result w/ json_encode might be:

{"VarCol":"string value","IntCol":"123"}

Is there any way to alter this and make TBS define the value as an integer or decimal if that's what it actually is in the database?  It seems to me that would be useful, when, e.g., using PHP's json_encode on $data to provide an AJAX call in my web application a result from a database query.  It would be nice if my AJAX data parsing code does not have to manually parse each number value as a number.

What I'd like to see instead, in this case is:

{"VarCol":"string value","IntCol": 123}

What do you think?  Am I missing something, or do you think this could be implemented with the access PHP gives you to the database connections?

jl
By: Skrol29
Date: 2012-05-25
Time: 09:39

Re: TbsSQL - GetRow question: varchar vs. integer, decimal data types

Hi John,

I've arranged the title of your post in order to note it is about TbsSQL.

TbsSQL does not change the values returned by the database driver.
Having string instead of integers or float is something I've already met with some database driver for PHP, in particular with PDO and PostgreSQL.

You can check by yourself the behavior of the driver: the connection resource or the connection object is referenced under $Db->Id.

Thus, the solution is to look at the PHP driver corresponding to your TbsSQL database type you are using and check if there is any option to change its way to return numerical differently.