Nikolay_888 Posted August 23, 2015 Share Posted August 23, 2015 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
myonlake Posted August 23, 2015 Share Posted August 23, 2015 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
Nikolay_888 Posted August 23, 2015 Author Share Posted August 23, 2015 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
myonlake Posted August 23, 2015 Share Posted August 23, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now