Home » U++ Library support » U++ SQL » Doubts on a sqlite query
Doubts on a sqlite query [message #38612] |
Sat, 29 December 2012 08:53  |
 |
forlano
Messages: 1207 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
I have two tables, TEAMS with 120 records and PLAYERS with 600 records. Each team contains 5 players. After a sort I need to update a field of TEAMS and another of PLAYERS. Both fields are called N. To perform this task I use the following procedure
void vegadb::SetPairingNumbers(int n, int arr_N[], Vector<int> ids)
{ int i, id, idp, np=1;
Sql sqlteam(sqliteVT);
Sql sqlplayer(sqliteVT);
Sql sqlp(sqliteVT);
for(i=0; i<n; i++) {
id = arr_N[i];
sqlteam.Execute("update TEAMS set N=? where ID=?", i+1, ids[i]);
sqlplayer.Execute("SELECT ID FROM PLAYERS WHERE TEAM_ID=? ORDER BY BOARD ASC", id); //retrieve players of team id by boards
while (sqlplayer.Fetch()) {
idp = (int) (sqlplayer[0]);
sqlp.Execute("update PLAYERS set N=? where ID=?", np++, idp); //set pairing number to the player idp
}
}
}
It works as expected. The problem is that it requires about 25 seconds on my notebook (intel celeron 1.70 GHz, 1Gb ram). It is not a monster machine but the number of records to be processed is not huge. Because I have not experience with sqlite I would like to know if this delay time is normal or maybe there is a faster way to write the query.
Thanks,
Luigi
|
|
|
Goto Forum:
Current Time: Mon Apr 28 20:52:49 CEST 2025
Total time taken to generate the page: 0.01354 seconds
|