newbie tcl & sql question 
Author Message
 newbie tcl & sql question

i don't get it,
i'm trying to print out the results of a sql query and the error i get
doesn't make sense. what am i doing wrong?
here's my test script:

#!/bin/sh
# the next line restarts using tclsh \

load fbsql.dll
sql connect localhost root "test"
sql selectdb test
sql startquery "select * from mt_category" -array category
puts "$category"
sql endquery
sql disconnect

the error:

can't read "category": no such variable

i'm using the FastBase MySQL + Tcl Interface Program and the
installation is fine.  i've declared the "category" array per
instructions from the documentation.
is there something i'm missing?



Tue, 22 Feb 2005 01:33:14 GMT  
 newbie tcl & sql question
Hi Bingo,

I don't know much about the sql startquery stuff, but it looks like it's
the line after the "startquery" that is causing problems (the 'puts
"$category"').  It looks as if you pass in the variable "category" into
startquery as an array, but you try and reference the whole array with
the puts.   Instead of 'puts "$category"', try:

puts [array get category]

That will put out each index and value in the array "category".  If the
category array is not populated by your query (i.e. there are no results
that match the sql statement), then you will get an empty line instead of
an error.

I could be wrong, since I don't know what the the sql calls do, but
that's what I would try if I had to debug your code.

Ben

Quote:

> i don't get it,
> i'm trying to print out the results of a sql query and the error i get
> doesn't make sense. what am i doing wrong?
> here's my test script:

> #!/bin/sh
> # the next line restarts using tclsh \

> load fbsql.dll
> sql connect localhost root "test"
> sql selectdb test
> sql startquery "select * from mt_category" -array category
> puts "$category"
> sql endquery
> sql disconnect

> the error:

> can't read "category": no such variable

> i'm using the FastBase MySQL + Tcl Interface Program and the
> installation is fine.  i've declared the "category" array per
> instructions from the documentation.
> is there something i'm missing?



Tue, 22 Feb 2005 01:42:06 GMT  
 newbie tcl & sql question


Quote:
>Hi Bingo,

>I don't know much about the sql startquery stuff, but it looks like it's
>the line after the "startquery" that is causing problems (the 'puts
>"$category"').  It looks as if you pass in the variable "category" into
>startquery as an array, but you try and reference the whole array with
>the puts.   Instead of 'puts "$category"', try:

>puts [array get category]

>That will put out each index and value in the array "category".  If the
>category array is not populated by your query (i.e. there are no results
>that match the sql statement), then you will get an empty line instead of
>an error.

>I could be wrong, since I don't know what the the sql calls do, but
>that's what I would try if I had to debug your code.

                        .
                        .
                        .
Quote:
>> the error:

>> can't read "category": no such variable

                        .
                        .
                        .
I salute a valiant speculation--but feel compelled to note
that it's unlikely to be fruitful.  While I don't know FastBase,
and my first thought was the same as yours, I'm certain that
Tcl will report
  can't read "category": variable is array
in the situation where category is an array and someone tries to
  puts $category

So what *is* the solution?  That'll have to wait the appearance
of more FastBase expertise here, I suspect.
--


Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



Tue, 22 Feb 2005 02:04:15 GMT  
 newbie tcl & sql question
My guess would be the select did not return any rows, therefore category was
never created.

I'd like to see the results of:

#!/bin/sh
# the next line restarts using tclsh \

load fbsql.dll
sql connect localhost root "test"
sql selectdb test
array set category {}
sql startquery "select * from mt_category" -array category
puts {category:}
parray category
puts {-------}
sql endquery
sql disconnect

Quote:



> >Hi Bingo,

> >I don't know much about the sql startquery stuff, but it looks like it's
> >the line after the "startquery" that is causing problems (the 'puts
> >"$category"').  It looks as if you pass in the variable "category" into
> >startquery as an array, but you try and reference the whole array with
> >the puts.   Instead of 'puts "$category"', try:

> >puts [array get category]

> >That will put out each index and value in the array "category".  If the
> >category array is not populated by your query (i.e. there are no results
> >that match the sql statement), then you will get an empty line instead of
> >an error.

> >I could be wrong, since I don't know what the the sql calls do, but
> >that's what I would try if I had to debug your code.
>                         .
>                         .
>                         .
> >> the error:

> >> can't read "category": no such variable
>                         .
>                         .
>                         .
> I salute a valiant speculation--but feel compelled to note
> that it's unlikely to be fruitful.  While I don't know FastBase,
> and my first thought was the same as yours, I'm certain that
> Tcl will report
>   can't read "category": variable is array
> in the situation where category is an array and someone tries to
>   puts $category

> So what *is* the solution?  That'll have to wait the appearance
> of more FastBase expertise here, I suspect.
> --


> Business:  http://www.Phaseit.net
> Personal:  http://starbase.neosoft.com/~claird/home.html

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester               | "The man who fights for his ideals is |

+--------------------------------+---------------------------------------+


Wed, 23 Feb 2005 01:52:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie problem with Scalable SQL & CW4

2. Newbie while || && question

3. newbie question RE which interface to SQL database to use

4. Newbie question on Tcl, Oratcl and cgi.tcl

5. tcl, aol, oracle & return PL/SQL Table

6. SQL stored procs & TCL

7. Newbie Question (Was: Newbie Question...)

8. RedHat 7.3 Expect & tcl newbie install

9. Newbie Q: Tcl & Support

10. Tcl/tk newbie & Dialog boxes

11. NEWBIE -- TCL & Sockets

12. Newbie drag & drop questions

 

 
Powered by phpBB® Forum Software