Page 1 of 2

DataBase Cursor

Posted: Mon Jun 15, 2015 9:10 pm
by chipsm
I have a routine where I open a database and read all of the table names into a field.
I use this data to select a table that I would like to do a query on. I cannot query the tables. is this because the pointer of cursor of the database is at the bottom and needs to be reset?

Re: DataBase Cursor

Posted: Mon Jun 15, 2015 11:33 pm
by MaxV
Hi,
I'd use revdataFromQuery() function:

Code: Select all

put "SELECT * FROM users ; " into tSQL
put revDataFromQuery(tab,return,connID,tSQL) into tRecords

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 1:23 pm
by chipsm
Thanks Max,
I actually found the problem.
I was beating my head against a wall that was somewhat impenetrable. I found out that LiveCode cannot process tableNames that have spaces in them. It throws a "revdberr" message.
Does anyone have a work around for this problem? Unfortunately I am not in control of the data source and I need a fix.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 2:18 pm
by Mikey
This isn't an LC issue. This is an SQL parser issue. You "quote" tablenames and fieldnames in SQL by surrounding them with square brackets.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 2:37 pm
by chipsm
Please elaborate!

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 2:50 pm
by Mikey
SELECT [field name with spaces embedded in it] FROM [table name with spaces in it]

This isn't an LC problem. It's a result of the way the SQL parser works (tokens are delimited by spaces).

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 2:56 pm
by chipsm
Thanks. I will try it immediately.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 3:05 pm
by chipsm
Mikey,
This is the code that I used and the same problem is still existing.

put "SELECT * FROM [465 halstead coppercube_10100_tl1]" into tSQL
put revDataFromQuery(tab,return,lDatabaseID,tSQL) into tRecords
put tRecords into field "Field2"

What am I doing wrong?

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 3:14 pm
by Mikey
Have you tried putting that query into valentina to play with it? Without looking at the schema it will be hard to tell exactly what's going on.
Are you sure the 465... is a table name and not an item value?

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 3:20 pm
by chipsm
Mikey,
I don't have Valentina.
The 465 is part of the table name.
I actually made a copy of the table without the spaces and the code works (this is before the square brackets). This is how I found out about the spaces in the Table Name and spaces.
So, the square brackets don't seem to be working for me yet.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 3:47 pm
by Mikey
Valentina is free to download and makes it easy to mess with databses, test queries, etc.
Again, without seeing the schema it will be difficult to help much more, but if you google spaces in table names you'll see more about it.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 3:56 pm
by chipsm
Mikey,
again...thanks for your help.

Re: DataBase Cursor

Posted: Tue Jun 16, 2015 4:02 pm
by chipsm
Mikey and all who need it.
Thanks to Mikey for helping me.
During a search I found the answer.
Use the tick symbols which you can usually find on your keyboard to the left from digit 1.
This Works.

Re: DataBase Cursor

Posted: Wed Jun 17, 2015 9:46 am
by MaxV
Does the following code work?

Code: Select all

put "SELECT * FROM " & quote & "465 halstead coppercube_10100_tl1" & quote & ";" into tSQL
put revDataFromQuery(tab,return,lDatabaseID,tSQL) into tRecords
put tRecords into field "Field2"

Re: DataBase Cursor

Posted: Wed Jun 17, 2015 2:25 pm
by chipsm
Hi Max,
I tried many iterations of quotes but I don't remember just using the keyword quote. I used "put quote &" and that didn't work.
I'll try that later.
Thanks.