You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by 38797715 <38...@qq.com> on 2020/08/26 11:10:29 UTC
How to solve the problem of single quotes in SQL statements?
Hi,
for example:
CREATE TABLE City ( ID INT(11), Name CHAR(35), CountryCode
CHAR(3), District CHAR(20), Population INT(11), PRIMARY KEY (ID,
CountryCode) ) WITH "template=partitioned, backups=1,
affinityKey=CountryCode, CACHE_NAME=City, KEY_TYPE=demo.model.CityKey,
VALUE_TYPE=demo.model.City";
INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
(1,'Ka'bul','AFG','Kabol',1780000);
name field's value contains single quotes.
The following writing will throw exceptions:
INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
(1,'Ka\'bul','AFG','Kabol',1780000);
INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
(1,'Ka\\'bul','AFG','Kabol',1780000);
INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
(1,"Ka'bul",'AFG','Kabol',1780000);
I wonder if there are any other solutions besides the PreparedStatement?
Re: How to solve the problem of single quotes in SQL statements?
Posted by 38797715 <38...@qq.com>.
ok,solved.
INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
(1,'Ka''bul','AFG','Kabol',1780000);
在 2020/8/26 下午7:10, 38797715 写道:
> Hi,
>
> for example:
>
> CREATE TABLE City ( ID INT(11), Name CHAR(35), CountryCode
> CHAR(3), District CHAR(20), Population INT(11), PRIMARY KEY (ID,
> CountryCode) ) WITH "template=partitioned, backups=1,
> affinityKey=CountryCode, CACHE_NAME=City, KEY_TYPE=demo.model.CityKey,
> VALUE_TYPE=demo.model.City";
>
> INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
> (1,'Ka'bul','AFG','Kabol',1780000);
>
> name field's value contains single quotes.
>
> The following writing will throw exceptions:
>
> INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
> (1,'Ka\'bul','AFG','Kabol',1780000);
>
> INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
> (1,'Ka\\'bul','AFG','Kabol',1780000);
>
> INSERT INTO City(ID, Name, CountryCode, District, Population) VALUES
> (1,"Ka'bul",'AFG','Kabol',1780000);
>
> I wonder if there are any other solutions besides the PreparedStatement?
>