Al Hoang

March 21, 2008

Being stupid on numrows() versus getting the actual result in LuaSQL

Filed under: programming, stupid — hoanga @ 9:53 am

I’m dumb. I had a bug in a checker script that I wrote and only noticed it recently when I bothered to RTFM. Can you spot the error? Probably most programmers will.

Non-working version

require "luasql.mysql"

env = luasql.mysql()
mysqlconn = env:connect("somedb", "someuser")
curs = mysqlconn:execute("
SELECT COUNT(*) FROM some_table WHERE col1 = ''foo")
print("Number of rows in $dlq queue is: ", curs:numrows())

Working version

require "luasql.mysql"

env = luasql.mysql()
mysqlconn = env:connect("somedb", "someuser")
curs = mysqlconn:execute("
SELECT COUNT(*) FROM some_table WHERE col1 = ''foo")
print("Number of rows in $dlq queue is: ", curs:fetch())
Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • Reddit
  • StumbleUpon
  • LinkedIn

Leave a Comment

You must be logged in to post a comment.

Powered by WordPress

Protected by AkismetBlog with WordPress