Lua and SQLite

Is the version of Lua and SQLite used in Corona the same as what you can learn about in a published book on the market? If so, does anyone have something they would recommend to read or is there something in the Corona docs that would show all the commands and syntax available to use on both subjects?

thanks.

Mike [import]uid: 23600 topic_id: 8016 reply_id: 308016[/import]

SQLite is a standard technology so I’m sure there are lots of books about it. I can’t recommend any specific books however and I’m wondering if such a book is even necessary; SQL isn’t that complicated a topic and there are tons of resources online. [import]uid: 12108 topic_id: 8016 reply_id: 28763[/import]

@cowtrax mike,

What is your programming experience? You might do well to do a few simple SQL tutorials at w3schools.com so you get an idea of the principles of db development.

Good luck.

[import]uid: 8045 topic_id: 8016 reply_id: 28777[/import]

Hello,

Thanks for your response. I have had many years of programming experience but my problem seems to maybe be more with SQLite. When I put it a simple command, such as a CREATE or INSERT, something that should be very simple and I have copied pretty much out of the SQLite tutorial, it does not work and I get a criptic error such that "an “=” is needed near the “INSERT” around line 43 or something like that. As far as I know, there is no “=” needed anywhere in that command. That is what is so frustrating. The other major frustration is the “program cycle” of Lua. I would like to put all my separate commands into “subroutines” and then just call them as needed but I have not seen how to do that in Lua. This is what is most frustrating about the process but i guess i just need to get submersed into the details. Just wish it wasn’t all trial and error. thanks for any advise you can give… mike [import]uid: 23600 topic_id: 8016 reply_id: 28786[/import]

it does not work and I get a criptic error such that "an “=” is needed near the “INSERT” around line 43

Well if you posted your code and the exact error message then maybe we can diagnose it. I’m guessing your issue is simply getting started doing anything at all with SQLite in Corona and then once you’re over that hump you’ll be off to the races. [import]uid: 12108 topic_id: 8016 reply_id: 28791[/import]

i think you are correct. it just seems that it should be very easy. Sql is not difficult but I get the feeling that there are certain rules either in corona or lua, such as having to put commands in brackets rather than just entering the command. Such as the example given in the sample code:

local tablefill3 =[[INSERT INTO Names VALUES (NULL,]]…testvalue1…[[’,’]]…testvalue2…[[’);]]
db:exec( tablefill )

rather than just: INSERT INTO Names VALUES (NULL, testvalue1,testvalue2)

the error message returned is: main.lua line 42 ‘=’ is expected near ‘INTO’
this is what is frustrating. the second command should work but does not.

thanks.

[import]uid: 23600 topic_id: 8016 reply_id: 28801[/import]

@cowtrax

Your SQL EXECUTE statement is attempting to execute on tablefill, it looks like it should be tablefill3 unless you’ve done some super fancy concotenating.

This:

local tablefill3 =[[INSERT INTO Names VALUES (NULL,]]…testvalue1…[[’,’]]…testvalue2…[[’);]]
db:exec( tablefill )

Should be like this:

local tablefill3 =[[INSERT INTO Names VALUES (NULL,]]…testvalue1…[[’,’]]…testvalue2…[[’);]]
db:exec( tablefill3 )

Try it and see if it works. If it does, let the community know so others might benefit from the answer. [import]uid: 8045 topic_id: 8016 reply_id: 28807[/import]

your right, the tablefill vs tablefill3 is just a typo. My real point is why does it need all the brackets and and concatenations. Why will the direct INSERT not work?

Such as: INSERT INTO Names VALUES (NULL, testvalue1,testvalue2)

I think in normal SQL this statement would work.

thanks. [import]uid: 23600 topic_id: 8016 reply_id: 28809[/import]

If it helps any, replace all the double brackets with quotation marks. That certainly helped me a lot. What you are doing is building strings with SQL commands and then executing those strings.

Come to think of it, they should probably rewrite the API examples with quotation marks. The brackets just confused me, but quotation marks make it very clear what exactly is going on. [import]uid: 12108 topic_id: 8016 reply_id: 28810[/import]

so what you are saying is. SQL commands have to be put into strings? If that is the case, ok, but does that mean that the “direct” INPUT as I did in my example does not work?

thanks. [import]uid: 23600 topic_id: 8016 reply_id: 28811[/import]

A “normal” SQL command will work.

The brackets is how the characters are escaped and to account for the variables.

As for me, it is confusing. It hurts my eyes. My way around code when it gets confusing is by writing it out as verbose as possible and then refactoring it for production.

[import]uid: 8045 topic_id: 8016 reply_id: 28813[/import]

When you say the “normal” sql command will work, you still have to put the brackets around the line? Is that right? Because if i substitute the [ with quotes ", the line does not work. I don’t mean to drag this on and on but I am just trying to understand it clearly.

thanks. [import]uid: 23600 topic_id: 8016 reply_id: 28814[/import]

Well you have to address the existing quote marks too. Basically what I mean is the SQL command

INSERT INTO Names VALUES (NULL, 1, 2);  

should be written into the string

"INSERT INTO Names VALUES (NULL, 1, 2);"  

Then it’s pretty clear what the concatenating is for:

"INSERT INTO Names VALUES (NULL, "..var1..", "..var2..");"  

The brackets is how the characters are escaped

Which characters? Doing it with quotation marks instead of brackets works for me, but I want to know if I am unwittingly causing myself problems. [import]uid: 12108 topic_id: 8016 reply_id: 28815[/import]

That helps. Thanks for your help. I am not sure though by what you mean by “characters are escaped”.

thanks again

Mike

one other thing. is there such a thing as a “subroutine” in Lua. Where you can put code and then “call” it from the main code. That way it organizes the code into smaller pieces and easier to maintain. [import]uid: 23600 topic_id: 8016 reply_id: 28821[/import]

is there such a thing as a “subroutine” in Lua. Where you can put code and then “call” it from the main code.

You mean a function?

local function something()  
 print("this is a test")  
end  
  
something()  

[import]uid: 12108 topic_id: 8016 reply_id: 28828[/import]

yes, like that… thanks very much for your help…

mike [import]uid: 23600 topic_id: 8016 reply_id: 28837[/import]