Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-16-2019, 09:21 PM   #1
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 18.04
Posts: 263

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.

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
.read insertpdata.sql
The file insertpdata.sql was created by phpmyadmin.

Thanks for your help in advance.

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

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

Rep: Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436Reputation: 1436
Please quote the complete error message you got. (Eg `backticking` fieldnames might be a MySql-specific feature.)

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
Senior Member
Registered: Mar 2004
Location: england
Distribution: Void, Debian, Puppy, Raspbian
Posts: 3,478

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"

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                                                             
I have given up using quotes, I do an awful lot of SQLite..

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.

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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 PM.

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