I posted this is a previous question :
if you are issuing a query like "select" use : executeQuery
if you are issuing a query like "insert" use : executeCommand (which will return a true or false if it failed or not)
but apparently executeCommand always returns true if the query is valid....
I need to know if the insert command actually inserted somethign into the database..... the executeCommand will still return true if the insert query didn't insert anything..
please help!
executeCommand always true?
I use postgresql database.... and I downloaded the driver called "8.1-405 JDBC 3" from this url :
http://jdbc.postgresql.org/download.html
and I changed a table name in the insert query to a table that doesn't exist.... and it did return false....
http://jdbc.postgresql.org/download.html
and I changed a table name in the insert query to a table that doesn't exist.... and it did return false....
Ok, this means that the driver is working correctly.
I use 90% of the times MySQL and sometime Access, when an INSERT command fails it usually spits an error out.
SFS should report all errors that the database engine produces...
Try another thing: take the SQL code of your insert that does not work and try to execute it directly in the db console or web admin interface.
What does it says? Do you get an error code?
I use 90% of the times MySQL and sometime Access, when an INSERT command fails it usually spits an error out.
SFS should report all errors that the database engine produces...
Try another thing: take the SQL code of your insert that does not work and try to execute it directly in the db console or web admin interface.
What does it says? Do you get an error code?
well... to be exatc... if I issue the query and it inserts a row the database colsole returns :
INSERT 0 1
if it doesn't insert a row it returns :
INSERT 0 0
if I make a typo in the query it returns :
ERROR: relation "tournameunt_scores" does not exist
so it must see "INSERT 0 1" and "INSERT 0 0" as both sucessfully running and thus "true"...
INSERT 0 1
if it doesn't insert a row it returns :
INSERT 0 0
if I make a typo in the query it returns :
ERROR: relation "tournameunt_scores" does not exist
so it must see "INSERT 0 1" and "INSERT 0 0" as both sucessfully running and thus "true"...
I would suggest to add a couple of queries before and after the insert to check if the operation was successfull.
You could exectute a
before and after the INSERT
You could exectute a
Code: Select all
SELECT COUNT(_any_field_name_here) FROM _your_table_
before and after the INSERT
Hello Lapo.
I've been watching this thread because I'm curious too about issues with database.
But it seems to me that you haven't understood the question
Does the executeCommand returns false only when the querry fails or also when 0 rows where affected?
How is SFS supposed to work?
I understand that you are looking for a driver issue. Hope you don't mind me posting here.
I'm just curious how would this behave with a MySql or Access driver.
I've been watching this thread because I'm curious too about issues with database.
But it seems to me that you haven't understood the question
Does the executeCommand returns false only when the querry fails or also when 0 rows where affected?
How is SFS supposed to work?
I understand that you are looking for a driver issue. Hope you don't mind me posting here.
I'm just curious how would this behave with a MySql or Access driver.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
Does the executeCommand returns false only when the querry fails or also when 0 rows where affected?
How is SFS supposed to work?
It's not much a problem with SFS here. It's more with how the database and driver return responses about the operations they do.
Sorry if answer a question with another question... but could you provide an example of an INSERT command that does not work, but it also doesn't report a database error?
In other words, an INSERT should always work unless you're duplicating a unique key, or there's a sythax error etc... In all these cases an error should be thrown by the DB which should be reported by SFS as well.
See what I mean?
Well, I wish I could give you a simple sql query... I only have the one I am using which if not formatted properly on your screen can look real ugly .
The following INSERT statement will only insert a row into the tournament_scores table if and only if it find another user in the tournaments table that is waiting for someone to play against (and we know they are waiting because the number of "players_so_far" in the tournament is less than the "no_players" allows for that tournament.
I know it's confusing... but it works. basically if it doesn't find someone to match the user against in a tournament, it just doesn't add a row.... it doesn't throw an error... there are just no rows added.
I hope this makes some sense.
INSERT INTO tournament_scores (unique_id, tourn_id, username, score) (SELECT "+unique_id+", tournaments.tourn_id, '"+username+"' as username, -1977 as score FROM tournaments, (select tourn_id, count(*) as no_players from tournament_scores GROUP BY tourn_id) as players_so_far WHERE tournaments.game_id = "+game_id+" and tournaments.tourn_id = players_so_far.tourn_id and tournaments.no_players > players_so_far.no_players LIMIT 1)
The following INSERT statement will only insert a row into the tournament_scores table if and only if it find another user in the tournaments table that is waiting for someone to play against (and we know they are waiting because the number of "players_so_far" in the tournament is less than the "no_players" allows for that tournament.
I know it's confusing... but it works. basically if it doesn't find someone to match the user against in a tournament, it just doesn't add a row.... it doesn't throw an error... there are just no rows added.
I hope this makes some sense.
INSERT INTO tournament_scores (unique_id, tourn_id, username, score) (SELECT "+unique_id+", tournaments.tourn_id, '"+username+"' as username, -1977 as score FROM tournaments, (select tourn_id, count(*) as no_players from tournament_scores GROUP BY tourn_id) as players_so_far WHERE tournaments.game_id = "+game_id+" and tournaments.tourn_id = players_so_far.tourn_id and tournaments.no_players > players_so_far.no_players LIMIT 1)
Return to “SmartFoxServer 1.x Discussions and Help”
Who is online
Users browsing this forum: No registered users and 54 guests