Forum

> > CS2D > Scripts > Error upon query
Forums overviewCS2D overview Scripts overviewLog in to reply

English Error upon query

3 replies
To the start Previous 1 Next To the start

old Error upon query

Marcell
Super User Off Offline

Quote
Hey,

I have LuaPower and using your MySQL, however, it can't seems to get all thing working fine.

Now, I have successfully made a connection and I am also able to select tables for example, but I was unable to insert any data into the tables.

The error itself is: FATAL ERROR [UNHANDLED EXCEPTION]: Attempt to call uninitialized function pointer

Here is my LUA code, so you can understand what I am trying to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
addhook("join", "onJoin")
addhook("minute", "saveStats")
addhook("say", "logChat")
addhook("say","onSay")

local mysql = require'mysql'

-- MySQL Connection Details:
sql_host = "localhost" -- Host
sql_user = "root" -- USER
sql_password = "1c%CIuROpD17" --Pass
sql_db_name = "cs2d" -- DBNAME
sql_port = 3306 

local con = mysql.connect(sql_host, sql_user, sql_password, sql_db_name, 'utf8')

function onJoin(id)
local usgn = player(id, "usgn")
local ip = player(id, "ip")
local name = player(id, "name")
local datime = os.date("%c")

     if usgn > 0 then
          -- con:query("INSERT INTO `logins`(`col_int`,`col_varchar`,`col_varchar`,`col_varchar`,`col_datetime`) VALUES (usgn, ip, name, datime)")
          print("a")
          msg("new player joined!")
     
     elseif usgn == 0 then
         -- con:query("INSERT INTO `logins`(`col_int`,`col_varchar`,`col_varchar`) VALUES (name, datime)")
     end
   
end

Unfortunately the query seems to be incorrect format or at least no real clue on which way could I make this happen.

I can't seems to debug it further. But I believe must be related the way I am trying to make the query, as for example selecting tables works with with the same connection.

Update: it's the issue of the MySQL library that generates a Windows generic error.
edited 1×, last 17.11.19 03:39:23 pm

old Re: Error upon query

DC
Admin Off Offline

Quote
You shouldn't share your password

Are you sure that values must be entered like this? I doubt that the variable will be resolved. Maybe you have to write:
1
con:query("INSERT INTO `logins`(`col_int`,`col_varchar`,`col_varchar`) VALUES ('" .. name .. "', '" .. datime .."')")
(of course name and datetime variables must be defined beforehand)

Another possible source of problems are the user permissions. Does the user have write permission for the table(s)?
edited 1×, last 17.11.19 04:14:12 pm

old Re: Error upon query

Hajt
User Off Offline

Quote
Try to use string.format e.g.:
1
con:execute(string.format([[INSERT INTO people VALUES ('%s', '%s')]], p.name, p.email))
Also these characters
`
are not needed in SQL query.

And I'm pretty sure your queries will stop working after some time because you are connecting to db only once in your script

old Re: Error upon query

Marcell
Super User Off Offline

Quote
@user DC: That's a randomly generated password just for this and MySQL is only locally accessible anyway

@user Hajt:
I tried many formats but none worked so far, I will try even the con:execute fails.


You both of you beloved

I think the issue was the way, I coded, and by closing the connection solved it.

Edit 2: Unfortunately the library is poor and therefore I can't really make the use of it, it randomly throws an error without any actual text that would help me to find out the error.
edited 2×, last 18.11.19 06:04:08 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview