executeCommand always true?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

executeCommand always true?

Postby Sparticus » 07 Mar 2006, 18:12

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!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Mar 2006, 20:04

what database and driver do you use?
as a test, try inserting a SQL synthax error... like a wrong table name or so. What happens? Do you still get true?
Lapo
--
gotoAndPlay()
...addicted to flash games
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 07 Mar 2006, 20:07

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....
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 07 Mar 2006, 20:14

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?
Lapo

--

gotoAndPlay()

...addicted to flash games
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 07 Mar 2006, 20:17

I tried that before and it sucessfuly run and just said "0 rows inserted"

no error... hmm... I'll continue trying things... I hope I can figure this out :(
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 07 Mar 2006, 20:37

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"...
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 08 Mar 2006, 06:05

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

Code: Select all

SELECT COUNT(_any_field_name_here) FROM _your_table_

before and after the INSERT
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 08 Mar 2006, 07:35

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.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Mar 2006, 06:34

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?
Lapo

--

gotoAndPlay()

...addicted to flash games
Sparticus
Posts: 227
Joined: 27 Feb 2006, 17:44
Location: Canada
Contact:

Postby Sparticus » 09 Mar 2006, 15:33

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)

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 25 guests