INSERT into SQL with special character in field

INSERT into SQL with special character in field

Postby Marc Vanzegbroeck » Thu Mar 19, 2015 2:07 pm

Hi,

I know this is not the forum for this, but I know a lot of people use SQL :)

I have a field 'NN(005)' in a SQL-database and want to insert something, but get an error because there is a '(' and ')' in the field-name.

I have try with:
Code: Select all  Expand view
INSERT INTO ucn_hwy (NAME,POINT_TYPE,NN(005)) VALUES ('CL09_3','PRMODNIM','5.0')

and with
Code: Select all  Expand view
INSERT INTO ucn_hwy (NAME,POINT_TYPE,'NN(005)') VALUES ('CL09_3','PRMODNIM','5.0')

but get always an error.
Is the a way to insert into something into this field?
The easyest way is to rename the field, but I prefer to use this.

Thanks.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: INSERT into SQL with special character in field

Postby Rick Lipkin » Thu Mar 19, 2015 3:47 pm

Marc

Surround your field name with brackets :

[This and that field name]

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: INSERT into SQL with special character in field

Postby Marc Vanzegbroeck » Thu Mar 19, 2015 4:23 pm

Rick,

I doesn't work, same problem...
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: INSERT into SQL with special character in field

Postby Rick Lipkin » Thu Mar 19, 2015 5:07 pm

Marc

This did not work ?

Rick Lipkin

Code: Select all  Expand view

INSERT INTO [ucn_hwy] ([NAME],[POINT_TYPE],[NN(005)]) VALUES ('CL09_3','PRMODNIM','5.0')
 
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: INSERT into SQL with special character in field

Postby Marc Vanzegbroeck » Thu Mar 19, 2015 5:18 pm

Rick,

With your example I get this error
Image

Without the brackets I had
Image

As you can see, the brackets are not allowed.
First, I had only an error 'near '(005'

I also tried
INSERT INTO ucn_hwy (NAME,POINT_TYPE,[NN(005)]) VALUES ('CL09_3','PRMODNIM','5.0')

but then I had the error
Image
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: INSERT into SQL with special character in field

Postby Rick Lipkin » Thu Mar 19, 2015 6:42 pm

Marc

Forgive the dumb question .. you are plugging in the correct val types into your fields ? Make sure your numeric fields accept decimals .. and not just integers.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2636
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: INSERT into SQL with special character in field

Postby Marc Vanzegbroeck » Thu Mar 19, 2015 7:00 pm

Rick,

All the fields are CHAR. Thats why I put '5.0' instead of 5.0 in it.
It als doesn't work if I want to write 'Test' in it...
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Re: INSERT into SQL with special character in field

Postby Marc Vanzegbroeck » Thu Mar 19, 2015 7:17 pm

Hi,

I have found the solution!!! :D :D :D
INSERT INTO ucn_hwy (NAME,POINT_TYPE,`NN(005)`) VALUES ('CL09_3','PRMODNIM','5.0')
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: INSERT into SQL with special character in field

Postby nageswaragunupudi » Fri Mar 20, 2015 1:40 pm

I saw the post just now.
While for Microsoft products like Access, MSSql, DBase drivers, etc, we use [ ] for escaping field names we need to use ` character (see below tilde ~ ) in MySql.

So `NN(005)` works.

For this purpose we provided nice translates.

Code: Select all  Expand view

cSql := "SQL INSERT INTO ucn_hwy (NAME,POINT_TYPE,NN(005)) VALUES ('CL09_3','PRMODNIM','5.0')"
 

would get translated as
"INSERT INTO `ucn_hwy` (`NAME`,`POINT_TYPE`,`NN(005)`) VALUES ('CL09_3','PRMODNIM','5.0')" if you are using MySql
or
"INSERT INTO [ucn_hwy] ([NAME],[POINT_TYPE],[NN(005)]) VALUES ('CL09_3','PRMODNIM','5.0')" if you are using MsSql,Access,etc.

FWH knows if you are using MySql or MSSql, etc when you open ado connection using FW_OpenAdoConnection.

If you use FWH support for ADO, you will never go wrong, save time and even generate a portable code
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10313
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 47 guests