Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Sqlite Delete not working [SOLVED]
Sqlite Delete not working [SOLVED] [message #34385] Sat, 19 November 2011 23:10 Go to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hello!
I'm trying Upp with Sqlite and an ArrayCtrl. So far this is an excellent tool for my tiny database apps. I got all the CRUD operations to work, but DELETE is not working.

Here is the code for DELETE:
String name = arr.Get(0);
Sql sql(db);
String x = "DELETE FROM PHONEBOOK WHERE NAME = '";
x += name;
x += "');";
sql.Execute(x);
arr.Remove(arr.GetCursor());


After this code gets executed the record is removed from ArrayCtrl arr, but the database doesn't change. When I refresh it the record is still there.

Any ideas?

Thanks

[Updated on: Sun, 20 November 2011 02:08]

Report message to a moderator

Re: Sqlite Delete not working [message #34386 is a reply to message #34385] Sat, 19 November 2011 23:48 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Anyone?
Re: Sqlite Delete not working [message #34387 is a reply to message #34386] Sun, 20 November 2011 00:15 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Maybe you need to send commit command to sqlite?
Re: Sqlite Delete not working [message #34388 is a reply to message #34387] Sun, 20 November 2011 00:20 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
I already tried:
db.Commit()


Didn't work either.
Re: Sqlite Delete not working [message #34389 is a reply to message #34385] Sun, 20 November 2011 01:13 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hi!
I studied the HomeBudget example and put this code together:
	SqlId PHONEBOOK("PHONEBOOK");
	SqlId NAME("name");
	String name = arr.Get(0);
	SQL = db;
	SQL.Begin();
	SQL * Delete(PHONEBOOK).Where(NAME == name);
	SQL.Commit();
	arr.Remove(arr.GetCursor());


And now it works! Very Happy

Looks like I better use this syntax. But I still haven't figured out why it didn't work using Execute().
Re: Sqlite Delete not working [message #34390 is a reply to message #34389] Sun, 20 November 2011 01:33 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
lectus wrote on Sun, 20 November 2011 01:13

But I still haven't figured out why it didn't work using Execute().

Hello.

Because of quotes for name and ")" at the end?
Look here for the raw delete examples.

[Updated on: Sun, 20 November 2011 01:34]

Report message to a moderator

Re: Sqlite Delete not working [message #34391 is a reply to message #34390] Sun, 20 November 2011 02:07 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Sender Ghost wrote on Sat, 19 November 2011 19:33

lectus wrote on Sun, 20 November 2011 01:13

But I still haven't figured out why it didn't work using Execute().

Hello.

Because of quotes for name and ")" at the end?
Look here for the raw delete examples.


Yeah true. The syntax of the DELETE command was wrong. lol
There was an extra ")" at the end. And the ' are required.
Now it worked.
The correct concatenation of the string is:
	String x = "DELETE FROM PHONEBOOK WHERE NAME = '";
	x += nome;
	x += "';";


Even though the examples you provided are in Tcl language. In this language "name" and name are the same since everything is a string in Tcl.

Re: Sqlite Delete not working [message #34392 is a reply to message #34391] Sun, 20 November 2011 05:36 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
lectus wrote on Sun, 20 November 2011 02:07


Yeah true. The syntax of the DELETE command was wrong. lol


The mentioned link suggested to use indexes for WHERE clause. In this case, you didn't need to quote it or use "(" and ")".
Consider to change your database schema and use ArrayCtrl::AddIndex or SqlArray.

[Updated on: Sun, 20 November 2011 06:05]

Report message to a moderator

Re: Sqlite Delete not working [message #34393 is a reply to message #34392] Sun, 20 November 2011 09:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12519
Registered: November 2005
Ultimate Member
Sender Ghost wrote on Sat, 19 November 2011 23:36

ArrayCtrl::AddIndex or SqlArray.


Beware: ArrayCtrl::AddIndex has nothing to do with DB indicies.
Re: Sqlite Delete not working [message #34394 is a reply to message #34393] Sun, 20 November 2011 09:59 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
mirek wrote on Sun, 20 November 2011 09:13


Beware: ArrayCtrl::AddIndex has nothing to do with DB indicies.

Ok, will take to note.
Thanks.
Re: Sqlite Delete not working [SOLVED] [message #34397 is a reply to message #34385] Sun, 20 November 2011 16:21 Go to previous message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
SqlArray is awesome.
I was just practicing with raw Sqlite3 support.
Previous Topic: Error when compiling native MySql with MSC9
Next Topic: sql + editstring
Goto Forum:
  


Current Time: Thu Jun 04 07:58:08 CEST 2020

Total time taken to generate the page: 0.01399 seconds