Insert from a field

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
parsec
Posts: 27
Joined: Fri Jan 09, 2015 5:24 pm

Insert from a field

Post by parsec » Wed Jan 13, 2016 1:19 am

I have this code

Code: Select all

on MouseUp
   global gConID
put field "FName" into tFName 
     put "INSERT INTO apps (appName) "  into tSQL
   put "VALUES (" & tFName & ");" after tSQL
   revExecuteSQL gConID, tSQL
   if the result is not 1 then
      answer warning the result
      exit  to top
   end if
   end mouseUp
that suppose to get the values from a FName
however I get this error "Microsoft ODBC SQL SERVER driver invalid column name" and what ever is the input from the field
here are my table and the table names
TABLE "apps" (
"appID" INT NOT NULL,
"appName" VARCHAR(50) NOT NULL,
"appRegCode" VARCHAR(50) NULL DEFAULT NULL,
"appUserID" VARCHAR(50) NULL DEFAULT NULL,
PRIMARY KEY ("appID")
)
I try to understand what I am doing wrong
Thank you
J

AxWald
Posts: 489
Joined: Thu Mar 06, 2014 2:57 pm

Re: Insert from a field

Post by AxWald » Wed Jan 13, 2016 9:48 am

Hi,

try:
put "VALUES ('" & tFName & "');" after tSQL

Since "appName" is a string you need some quotes around. And since you're constructing the string with concatenation (that already uses quotes) the use of " ' " (single quote) is the way to go!

Have fun!
Livecode programming until the cat hits the fan ...

parsec
Posts: 27
Joined: Fri Jan 09, 2015 5:24 pm

Re: Insert from a field

Post by parsec » Fri Jan 15, 2016 3:49 pm

thank you for the help
May I ask you if that is the proper and most efficient way to do this, is any other way as well
Thank you again

AxWald
Posts: 489
Joined: Thu Mar 06, 2014 2:57 pm

Re: Insert from a field

Post by AxWald » Sun Jan 17, 2016 6:42 pm

Hi,
parsec wrote:May I ask you if that is the proper and most efficient way to do this, is any other way as well
Well, I'm used to construct strange SQL statements "manually", since I'm doing this in MS Access VBA since ages - after a while you get quite accustomed to work with multitudes of:

Code: Select all

( ) , ' " & ...
;-)

If you had a function:

Code: Select all

function swote Txt    -- usefull to get those nasty 'singlequotes'
   return "'" & txt & "'"
end swote
you could write:

Code: Select all

put "VALUES (" & swote(tFName) & ");" after tSQL
as well.

I'm sure there are other ways to make it easier though. You just have to make sure to have the data formatted in a way that the target SQL engine understands ...

Have fun!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Databases”