1. Post #121
    syl0r's Avatar
    January 2012
    423 Posts
    I'd guess this is because Lua's C errors are going to jump straight past the destructor of any C++ object. That'd mean the lock guard here never unlocks.

    It's annoying and also means there's probably many other bugs in the module, but that's how Lua's C API works.
    Yup, that's what's causing it. Unfortunately that is what you will get when you are mixing two languages that have vastly different language constructs (and both of which suck).
    I was aware of the RAII issue with LUA and I did go through most of the code to find any issues, but I somehow missed that one. The sad thing is that some scenarios (such as stack overflow or out of memory) a crash is unavoidable. Even without RAII, a longjump will always fuck up your code.

    As a sidenote, there's only very few scenarios where you should use db:escape(). A prepared query (if possible) should always be preferred.

  2. Post #122
    BlackCetha's Avatar
    June 2014
    4 Posts
    I am currently running into issues. It seems to me like the callback just doesnt fire.

    This is how my function works:
    Code:
    local queryDoesExist = db:prepare( [[
      SELECT id FROM items
      WHERE name = ?
    ]] )
    
    function doesExist ( name, callback )
      print "0"
    
      queryDoesExist:setString( 1, name )
    
      function queryDoesExist:onSuccess ( rows )
        print "1"
    
        return callback( #rows ~= 0 )
      end
    
      function queryDoesExist:onError ( err )
        print( "Error: " .. err )
      end
    
      print "2"
    
      queryDoesExist:start()
    end
    In this example, it works if it is instantly run after the database connected.
    Calling it with lua_run or a proxy function doesn't work. It would print "0" and "2".

  3. Post #123

    August 2014
    349 Posts
    I am currently running into issues. It seems to me like the callback just doesnt fire.

    This is how my function works:

    In this example, it works if it is instantly run after the database connected.
    Calling it with lua_run or a proxy function doesn't work. It would print "0" and "2".
    I just tested your code and it works fine for me.

    I suggest you clean it up a little bit though.

    Code:
    function doesExist(name, callback)
    	local q = [[SELECT id FROM items WHERE name = ?;]]
    	local query = db:prepare(q)
    
    	query:setString(1, name)
    
    	function query:onError(err)
    		print("Error "..err)
    	end
    	function query:onSuccess(data)
    		callback(data[1] and true or false)
    	end
    
    	query:start()
    end