Jump to content

How to check execution of dbExec?


Nikolay_888

Recommended Posts

Hello. :)

I read:

'To update values in database, we need to use dbExec.'

But how can I check, executes this dbExec query or not, if this function (from wiki)

returns true unless the connection is incorrect, in which case it returns false.

So, if the connection is correct, and the query is incorrect, function returns true.

How to check, is values updated/inserted with dbExec?

Thank you :)

Link to comment

There is a @@ROWCOUNT and @@ROWCOUNT_BIG in T-SQL but this probably does not relate to you.

You can create a procedure in SQL and get the number of affected results that way. But that you would have to create to every SQL statement you make. No shorthands as far as I know.

Link to comment

What about to use dbQuery instead dbExec.

For example:

addaccount = dbQuery( pl_con, "INSERT INTO players VALUES (?,?)", id, name) 
local poll, num_rows = dbPoll (addaccount, -1) 
if poll and num_rows == 1 then 
   --register OK 
else 
   --register fail 
end 
  

It works in my situation, but is it a right way? I mean is this code will cause errors or problems in another place?

Link to comment

You are correct. I forgot about that.

You can use num_rows_affected from dbPoll.

If the result is returned nil, it means the result has not yet been retrieved. If the result is returned false, it means the query failed for some reason. If the result returns a table, it went through.

You can then use num_rows_affected > 0 to test if any rows were affected.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...