• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 998
  • Last Modified:

how to insert and display data in sqlite3 using bash?

i have three variables holding information
var1=CSI6221 Project 1    2015 Semester 1
var2=WED
var3=12:30 - 13:30
var4=ML 03.102 Tutorial Room
sqlite3 test.db "create table  timetable_info (ID INTEGER
       PRIMARY KEY,unitinfo TEXT,day TEXT,time TEXT,location TEXT);" ### created a table like this
sqlite3 test.db  "insert into timetable_info (unitinfo,day,time,room) values ('$var1', '$var2', '$var3' '$var4');" inserted values this way.
sqlite3 test.db  "select * from timetable_info;"  ### i tried to display data..
i ended up with the message  Error:::: near "'ML 03.102 Tutorial Room'": syntax error


can any help what this means?


thank you
0
vishnu kalakota
Asked:
vishnu kalakota
1 Solution
 
johnsoneSenior Oracle DBACommented:
Because you have spaces in your variable values.  It should be this:

var1="CSI6221 Project 1    2015 Semester 1"
var2="WED"
var3="12:30 - 13:30"
var4="ML 03.102 Tutorial Room"
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You missed a comma in your insert statement and and you have the wrong column name for column #4.

Change your insert statement to this:
[gerwin@localhost tmp]$ sqlite3 test.db  "insert into timetable_info (unitinfo,day,time,location) values ('$var1', '$var2', '$var3','$var4');"

Open in new window


and test/display:
[gerwin@localhost tmp]$ sqlite3 test.db  "select * from timetable_info;"
1|CSI6221 Project 1    2015 Semester 1|WED|12:30 - 13:30|ML 03.102 Tutorial Room
[gerwin@localhost tmp]$ 

Open in new window

0
 
vishnu kalakotaAuthor Commented:
Stuck with the silly mistake since couple of days..
thanks very much...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now