Jump to content

SQLite


WhoAmI

Recommended Posts

Posted

Hi guys.

I just want to now how I can create a table includes column with auto increment?

executeSQLQuery("CREATE TABLE IF NOT EXISTS name (id NOT NULL AUTO_INCREMENT, other_stuff TEXT)") 

And it outputs error. Anyone knows?

Posted
executeSQLQuery("CREATE TABLE IF NOT EXISTS name (id INT NOT NULL AUTO_INCREMENT, other_stuff TEXT)") 

This should work, you didn't specify the id type

Posted
executeSQLQuery("CREATE TABLE Persons(ID int NOT NULL AUTO_INCREMENT,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255),PRIMARY KEY (ID))") 
  

Try that that was directly copied from some mysql website, If it doesn't work it's maybe not supported by MTA executeSQLQuery

Posted

Nah. Same error. When im writing NOT_NUL, instead of NUT NULL there is no error, but when im getting the data, I can't get id cloumn's values.

Posted
handler = dbConnect("sqlite", "file.db") 
dbQuery(handler, "CREATE TABLE IF NOT EXISTS Persons(ID int NOT NULL AUTO_INCREMENT,LastName varchar(255) NOT NULL,FirstName varchar(255),Address varchar(255),City varchar(255))") 

Well, I did sth like this, but when im starting resource, file.db is clear.

@EDIT: When i'm deleting "NOT NULL", everything is okey. Does MTA not support "NOT NULL"?

Posted
@EDIT: When i'm deleting "NOT NULL", everything is okey. Does MTA not support "NOT NULL"?

Gues not then, I did it with mysql connection and everything worked fine, so it's working now ?

Posted

Yea, I did same thing in MySQL and it works. Was disappointed why it isn't working here.

It isn't working, when im deleting this, the column "ID" returns just nil.

There is my code:

handler = dbConnect("sqlite", "file.db") 
dbQuery(handler, "CREATE TABLE Persons(ID INT AUTO_INCREMENT NOT NULL, LastName varchar(255))") 
  
addCommandHandler("add", 
    function () 
        dbQuery(handler, "INSERT INTO Persons(LastName) VALUES (?)", "Jacob") 
    end 
) 
  
addCommandHandler("check", 
    function () 
        local data = dbQuery(handler, "SELECT * FROM Persons") 
        if (data) then 
            local result = dbPoll(data, -1) 
            for k,v in ipairs(result) do outputChatBox(v["id"]..v["LastName"]) end 
        end 
    end 
) 

And the v["id"] gives nil.

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