Jump to content

[SOLVED] SQLite - SQL Logic error or missing database


cheez3d

Recommended Posts

  
dbExec(getElementData(resourceRoot,"dayz:resource.settings.database"),"INSERT INTO `players` (`serial`,`password`,`data`) VALUES (?,?,?);","serial","password","3,4") 
  

This is a test query that should insert some data into the database but it is not working. I have already tested and the connection element exists, so there should be a problem inside the query that I cannot figure out. Can anyone help please? I've already searched on Google and didn't find anything.

ERROR: dbExec failed (1); SQL logic error or missing database

Edited by Guest
Link to comment

I still need help with this. Also tried using dbConnect inside, instead of getElementData and it is the same thing. I also use outputChatBox and it returns an userdata. Here are some screenshots from SQLite Browser. I think the problem is the id column, but I'm not sure.

HLWn9LF.png

GfbxWjb.png

As you can see the table is empty.

Link to comment
  
dbExec (dbConnect(getElementData(resourceRoot,"dayz:resource.settings.database"),"INSERT INTO `players` VALUES (?,?,?,?);",23,"serial","password","3,4") 
  

This query works just fine (if i do not supply the columns to insert into) but the problem is that id is an auto increment column and I don't want to insert the values manually.

EDIT: Got the problem! But I still have a dilemma. The creation query will create the id column that has the NOT NULL property. When I insert new values into the table I don't specify the id and that is why it's giving me the error. So, I remove NOT NULL from id and now this query works but there is no id value automatically assigned (it remains empy).

  
-- CREATION QUERY 
dbExec(getElementData(resourceRoot,"dayz:resource.settings.database"),"CREATE TABLE IF NOT EXISTS `players` (`id` INT PRIMARY KEY,`serial` TEXT NOT NULL,`password` TEXT NOT NULL,`data` TEXT NOT NULL);") 
-- INSERT QUERY 
dbExec(getElementData(resourceRoot,"dayz:resource.settings.database"),"INSERT INTO `players` (`serial`,`password`,`data`) VALUES (?,?,?);","serial","password","3,4") 
  

NAsY6qb.png

EDIT 2: Well, after I documented myself a little bit I found out that you must use a query like this:

  
dbExec(getElementData(resourceRoot,"dayz:resource.settings.database"),"CREATE TABLE IF NOT EXISTS `players` (`id` INTEGER PRIMARY KEY AUTOINCREMENT,`serial` TEXT NOT NULL,`password` TEXT NOT NULL,`data` TEXT NOT NULL);") 
  

There are some weird differences between MySQL queries and SQLite queries. Problem finally solved!

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...