LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 08:21 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
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, 08:27 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Just a guess...use double quotes and don’t escape the apostrophes.
 
Old 11-16-2019, 11:57 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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 02:11 AM.
 
1 members found this post helpful.
Old 11-18-2019, 09:13 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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 09:31 AM.
 
  


Reply



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 01:59 AM
[SOLVED] How to pass a single quote inside of a single quote... trist007 Linux - Newbie 2 02-09-2011 07:07 PM
[SOLVED] How to escape single quote btacuso Linux - Newbie 3 03-11-2010 10:58 AM
sed : Convert double quote to singe quote pgb_710 Programming 6 01-21-2010 07:59 AM
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 04:37 PM

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

All times are GMT -5. The time now is 09:52 AM.

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
Open Source Consulting | Domain Registration