WhoAmI Posted February 26, 2014 Share Posted February 26, 2014 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? Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 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 Link to comment
cheez3d Posted February 26, 2014 Share Posted February 26, 2014 executeSQLQuery("CREATE TABLE IF NOT EXISTS `dbName` (ID INT(5) NOT NULL AUTO_INCREMENT, Name TEXT NOT NULL), PRIMARY KEY (ID)") Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 Both same error. http://snag.gy/wQyia.jpg Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 Both same error.http://snag.gy/wQyia.jpg Try dropping table Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 There's nothing to drop. Couse of error, tables didn't create. Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 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 Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 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. Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 What about dbQuery? I'll try. Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 I think that dbQuery should work Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 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"? Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 @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 ? Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 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. Link to comment
Wei Posted February 26, 2014 Share Posted February 26, 2014 v["id"] should be v["ID"] Link to comment
WhoAmI Posted February 26, 2014 Author Share Posted February 26, 2014 Well, I did this, using https://addons.mozilla.org/pl/firefox/a ... e-manager/ and files .sqlite. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now