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 » How to view immediately the primary key in SqlArray
How to view immediately the primary key in SqlArray [message #38842] Wed, 23 January 2013 11:28 Go to next message
alca is currently offline  alca
Messages: 4
Registered: December 2012
Location: Italy
Junior Member
Hello to all.

I'm trying to edit an sqlite table with SqlArray and I would show the id of each row in the first column.
It is the PRIMARY_KEY AUTO_INCREMENT field and I need only to show it (not edit it).

I used this code grabbed frome some examples:
EditString _id, _desc, _cost;
...
_arr.SetTable(MY_TABLE).AppendingAuto();
_arr.AddKey(ID);
_arr.AddColumn(ID, t_("ID") ).Edit(_id).NoEdit();
_arr.AddColumn(DESC, t_("Descr")).Edit(_desc);
_arr.AddColumn(COST, t_("Cost") ).Edit(_cost);
_arr.Appending().Removing();
_arr.SetOrderBy(ID);
_arr.Query();

That almost works, but I have problem when I add new rows:
the id editstring is left blank in SqlArray row until I exit the applicatin and restart it.
It seems that the id is showed only for consolidated rows in the table.
What I need is to see immediately the generated id as the used click "Insert record" context menu.

Can someone give me any hint?

Ah, and another newbie question:
can I set a callback in response of each modification (insert/edit/delete) on the table?
_arr <<= THISBACK(UpdatedTable);
can be the answer?

Many tanks in advance to all you guru, and keep on with U++! Smile
Ciao
Alberto

[Updated on: Wed, 23 January 2013 11:29]

Report message to a moderator

Re: How to view immediately the primary key in SqlArray [message #38845 is a reply to message #38842] Wed, 23 January 2013 14:18 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
I did not try, but I think, this code would be better:
_arr.SetTable(MY_TABLE).AppendingAuto();
_arr.AddColumn(ID, t_("ID") );
_arr.AddColumn(DESC, t_("Descr")).Edit(_desc);
_arr.AddColumn(COST, t_("Cost") ).Edit(_cost);
_arr.Appending().Removing();
_arr.SetOrderBy(ID);
_arr.Query();

I removed AddKey as the first column is the key, and removed the editor from the ID column.
icon14.gif  Re: How to view immediately the primary key in SqlArray [message #38846 is a reply to message #38845] Wed, 23 January 2013 16:04 Go to previous messageGo to next message
alca is currently offline  alca
Messages: 4
Registered: December 2012
Location: Italy
Junior Member
You've got it!
The ID now is showed as the new row is added. Perfect.

So, as far I understand, AddKey() is to be used only if the key is not showed in the SqlArray row.

Many Thanks.
Alberto

Re: How to view immediately the primary key in SqlArray [message #38849 is a reply to message #38846] Wed, 23 January 2013 22:36 Go to previous message
zsolt is currently offline  zsolt
Messages: 696
Registered: December 2005
Location: Budapest, Hungary
Contributor
alca wrote on Wed, 23 January 2013 16:04


So, as far I understand, AddKey() is to be used only if the key is not showed in the SqlArray row.


Sure
Previous Topic: How to use Sqlite BLOB type in U++ schema files?
Next Topic: Reading S_xxxx records from Sql
Goto Forum:
  


Current Time: Sat Apr 20 04:09:57 CEST 2024

Total time taken to generate the page: 0.02837 seconds