Jump to content

[SOLVED] SQLite - SQL Logic error or missing database


cheez3d

Recommended Posts

Posted (edited)
  
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
Posted

The problem is with your database handler, because I just tried it and works fine.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted

Post the dbConnect script line.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
  
local connection = dbConnect("sqlite","resources/storage/dayz.db") 
setElementData(resourceRoot,"dayz:resource.settings.database",connection,false) 
  

I also execute a SELECT query before that INSERT and it works fine.

Posted

And the other code is in the same resource as that?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Tried executing it using "connection" instead of getting the element data?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
  
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!

Posted

I got same problem and I was using database manager to create column with auto increment property. Anyway, good that you found the problem, now I know how to build tables inside function. :D

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