1. Eusql question

Hi,
I am  accessing the Eusql database in a wxEuphoria program and want to 
display the data that I am putting into a line of data into a listbox.  
I am reading several records so I am using the FOR loop to access the  
records and then another loop to access the fields. I can display the 
data if it is described as text, but I cannot display the data when it 
is a number.  I am trying to use the command
fn = (sql[1][x1][x2])
    ft= get_field_datatype ( thisdb, thistbl,fn)
If I get ft I would use this to
for x1 = 1 to listlen do
    for x2 = 1 to 13 do
        trace(1)
        fn = (sql[1][x1][x2])
        ft= get_field_datatype ( thisdb, thistbl,fn)
        if ft = "9" then
            line = line &        sprintf("%d",sql[2][x1][x2])&", "
        else
            line = line &(sql[2][x1][x2])&", "
        end if
    end for
    add_item(Combo8, line)
end for

Thanks for any help
Jim

new topic     » topic index » view message » categorize

2. Re: Eusql question

sixs wrote:
> 
> Hi,
> I am  accessing the Eusql database in a wxEuphoria program and want to 
> display the data that I am putting into a line of data into a listbox.  
> I am reading several records so I am using the FOR loop to access the  
> records and then another loop to access the fields. I can display the 
> data if it is described as text, but I cannot display the data when it 
> is a number.  I am trying to use the command
> fn = (sql[1][x1][x2])
>     ft= get_field_datatype ( thisdb, thistbl,fn)
> If I get ft I would use this to
> for x1 = 1 to listlen do
>     for x2 = 1 to 13 do
>         trace(1)
>         fn = (sql[1][x1][x2])
>         ft= get_field_datatype ( thisdb, thistbl,fn)
>         if ft = "9" then
>             line = line &        sprintf("%d",sql[2][x1][x2])&", "
>         else
>             line = line &(sql[2][x1][x2])&", "
>         end if
>     end for
>     add_item(Combo8, line)
> end for

What type of data is in the field?  Rather than hardcoding "9", you 
should use the constants that EuSQL provides:

EUSQL_EU_ATOM
EUSQL_EU_INTEGER
EUSQL_EU_OBJECT
EUSQL_EU_SEQUENCE
EUSQL_EU_TEXT
EUSQL_EU_BINARY
EUSQL_AUTONUMBER

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: Eusql question

I am using  the autonumber, integer definition for some fields, and text 
for the rest
is the first line going to give me the field name?
fn = (sql[1][x1][x2])
I can't access the sql  in get_field_datatype: this is the line I bomb on
ft= get_field_datatype ( thisdb, thistbl,fn)
====================
fn = (sql[1][x1][x2])
        ft= get_field_datatype ( thisdb, thistbl,fn)
        if ft = EUSQL_EU_INTEGER then
            line = line &        sprintf("%d",sql[2][x1][x2])&", "
        else
            line = line &(sql[2][x1][x2])&", "
   

Matt Lewis wrote:

>
>
>posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
>
>sixs wrote:
>  
>
>>Hi,
>>I am  accessing the Eusql database in a wxEuphoria program and want to 
>>display the data that I am putting into a line of data into a listbox.  
>>I am reading several records so I am using the FOR loop to access the  
>>records and then another loop to access the fields. I can display the 
>>data if it is described as text, but I cannot display the data when it 
>>is a number.  I am trying to use the command
>>fn = (sql[1][x1][x2])
>>    ft= get_field_datatype ( thisdb, thistbl,fn)
>>If I get ft I would use this to
>>for x1 = 1 to listlen do
>>    for x2 = 1 to 13 do
>>        trace(1)
>>        fn = (sql[1][x1][x2])
>>        ft= get_field_datatype ( thisdb, thistbl,fn)
>>        if ft = "9" then
>>            line = line &        sprintf("%d",sql[2][x1][x2])&", "
>>        else
>>            line = line &(sql[2][x1][x2])&", "
>>        end if
>>    end for
>>    add_item(Combo8, line)
>>end for
>>    
>>
>What type of data is in the field?  Rather than hardcoding "9", you 
>should use the constants that EuSQL provides:
>
>EUSQL_EU_ATOM
>EUSQL_EU_INTEGER
>EUSQL_EU_OBJECT
>EUSQL_EU_SEQUENCE
>EUSQL_EU_TEXT
>EUSQL_EU_BINARY
>EUSQL_AUTONUMBER
>
>Matt Lewis
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

4. Re: Eusql question

sixs wrote:
> 
> I am using  the autonumber, integer definition for some fields, and text 
> for the rest
> is the first line going to give me the field name?
> fn = (sql[1][x1][x2])
> I can't access the sql  in get_field_datatype: this is the line I bomb on
> ft= get_field_datatype ( thisdb, thistbl,fn)
> ====================
> fn = (sql[1][x1][x2])
>         ft= get_field_datatype ( thisdb, thistbl,fn)
>         if ft = EUSQL_EU_INTEGER then
>             line = line &        sprintf("%d",sql[2][x1][x2])&", "
>         else
>             line = line &(sql[2][x1][x2])&", "

What are x1 and x2?  You're subscripting too many times.   The first element of
a returned query are the field names, so you're getting a single character
in a field name.  There's a much easier way to get the data type of fields
in a query.  The third element of the returned query contains the datatypes.
It looks like you could just as easily check to see if sql[2][x1][x2] is an
atom, since you might have multiple types of numbers.

For instance, the query:
object sql
sql = run_sql( "select name, id from mytable" )

-- should return something like:
-- {
--   { "NAME", "ID" },
--   {
--     {"Jim", 1 },
--     {"Matt", 2}
--   }
--   { EUSQL_EU_TEXT, EUSQL_AUTONUMBER }
-- }


Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu