FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour INSERT into SQL with special character in field
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 02: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 (fw): Select all Collapse
INSERT INTO ucn_hwy (NAME,POINT_TYPE,NN(005)) VALUES ('CL09_3','PRMODNIM','5.0')

and with
Code (fw): Select all Collapse
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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 03:47 PM

Marc

Surround your field name with brackets :

[This and that field name]

Rick Lipkin

Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 04:23 PM

Rick,

I doesn't work, same problem...

Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 05:07 PM
Marc

This did not work ?

Rick Lipkin

Code (fw): Select all Collapse
INSERT INTO [ucn_hwy] ([NAME],[POINT_TYPE],[NN(005)]) VALUES ('CL09_3','PRMODNIM','5.0')
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 05:18 PM
Rick,

With your example I get this error


Without the brackets I had


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
Regards,

Marc



FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 06: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

Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 07: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 07:11 PM
Marc,

check if your field name is right for MySQL rules:

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

EMG
Posts: 1195
Joined: Mon Oct 17, 2005 05:41 AM
Re: INSERT into SQL with special character in field
Posted: Thu Mar 19, 2015 07: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: INSERT into SQL with special character in field
Posted: Fri Mar 20, 2015 01: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 (fw): Select all Collapse
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

Continue the discussion