LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2019, 09:21 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 16.04
Posts: 243

Rep: Reputation: 8
How to correct syntax error created by using escape for single quote (\') in sqlite3


I am trying to use an INSERT statement in an sqlite3 database that came from MySql.

Code:
INSERT INTO `pdata` (`id`, `First`, `Last`, `Name`, `CatId`, `Sub`, `Location`, `Phone`, `Cell`, `Email`, `Notes`) VALUES
(3, 'Beth', 'Jean\'s Friend', 'Jean\'s Friend, Beth', 6, 0, '', '208.255.8015', '', '', 'Jeans Friend');
The escapes (\') create syntax errors in sqlite3.

How do I get around this in sqlite3? I am trying to
Code:
.read insertpdata.sql
The file insertpdata.sql was created by phpmyadmin.

Thanks for your help in advance.

R
 
Old 11-16-2019, 09:27 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,075

Rep: Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387Reputation: 1387
Just a guess...use double quotes and donít escape the apostrophes.
 
Old 11-17-2019, 12:57 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,901

Rep: Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380Reputation: 1380
Please quote the complete error message you got. (Eg `backticking` fieldnames might be a MySql-specific feature.)
Edit: https://www.sqlite.org/faq.html#q14

Last edited by NevemTeve; 11-17-2019 at 03:11 AM.
 
1 members found this post helpful.
Old 11-18-2019, 10:13 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Slack, Debian, Mint, Puppy, Raspbian
Posts: 3,474

Rep: Reputation: 222Reputation: 222Reputation: 222
Don't need to use quotes, in fact single quotes are strings, only "" will be interpolated.
You do NOT need to backslash the single quotes you can do: "John's"

Code:
sqlite> INSERT INTO "pdata"
   ...>         ("id", "First", "Last", "Name", "CatId", "Sub",
   ...>         "Location", "Phone", "Cell", "Email", "Notes")
   ...> 
   ...>         VALUES (3, "Beth", "Jean's Friend", "Jean's Friend, Beth",
   ...>         6, 0, "", "208.255.8015", "",
   ...>         "", "Jean's Friend");
sqlite> select first, last, name from pdata
   ...> ;
First       Last                  Name                                                                            
----------  --------------------  --------------------------------------------------------------------------------
Beth        Jean's Friend         Jean's Friend, Beth                                                             
sqlite>
I have given up using quotes, I do an awful lot of SQLite..

observe:
Code:
sqlite> select tile_data, "tile_data", 'tile_data'   from tiles limit 1;

  Give your very best today.  Heaven knows it's little enough.
  Give your very best today.  Heaven knows it's little enough.
  tile_data

Last edited by bigearsbilly; 11-18-2019 at 10:31 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell: how to escape (or not escape) $ within an echo statement? Paul_N Linux - Newbie 2 04-05-2016 02:59 AM
[SOLVED] How to pass a single quote inside of a single quote... trist007 Linux - Newbie 2 02-09-2011 08:07 PM
[SOLVED] How to escape single quote btacuso Linux - Newbie 3 03-11-2010 11:58 AM
sed : Convert double quote to singe quote pgb_710 Programming 6 01-21-2010 08:59 AM
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 05:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration