ma2med Posted May 8, 2015 Share Posted May 8, 2015 Hi, I tried to get result of SQL operation from a custom db but it won't work, why that? connection = dbConnect( "sqlite", "groups.db" ) function test(account, key) for i, values in ipairs(getAccounts()) do if getAccountName(values) == getAccountName(account) then local query = dbQuery(connection, "SELECT value FROM groups WHERE userid = ".. i .." and key = '".. key .."'") return dbPoll(query, -1) end end end-- addCommandHandler("lol", function(p) if not isGuestAccount(getPlayerAccount(p)) then for i, v in ipairs(test(getPlayerAccount(p), "Ranks")) do outputChatBox(v, root) end end end) Link to comment
WhoAmI Posted May 8, 2015 Share Posted May 8, 2015 Do you have groubs.db in your resource folder and is it in meta? Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 It's not in meta, should I add it? Which tag is it, script, file ? Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 I think working now, thanks WhoAmI. EDIT: Same result, I wasn't login I forgot. It's still print nothing. Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 Nope. When I put addCommandHandler("lol", function(p) for i, v in ipairs(getDBAccountData(getPlayerAccount(p), "Ranks")) do outputChatBox(v, root) end end) It's show nothing but when I put addCommandHandler("lol", function(p) outputChatBox(getDBAccountData(getPlayerAccount(p), "Ranks"), root) end) It's wrote that the result is table. Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 When I execute it with SQLite it's show 1 row. Link to comment
TAPL Posted May 8, 2015 Share Posted May 8, 2015 addCommandHandler("lol", function(p) for i, row in ipairs(getDBAccountData(getPlayerAccount(p), "Ranks")) do for column, value in pairs(row) do outputChatBox(column..": "..value) end end end) Read the second example in the wiki and you will understand. https://wiki.multitheftauto.com/wiki/DbPoll Also you don't need to add the db file in the meta. Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 Hi, it's still not working sorry but I don't understood the second example that the same thing or maybe I am wrong? Link to comment
TAPL Posted May 8, 2015 Share Posted May 8, 2015 Try. connection = dbConnect( "sqlite", "groups.db" ) function test(account, key) for i, values in ipairs(getAccounts()) do if values == account then local query = dbQuery(connection, "SELECT value FROM groups WHERE userid =? AND key =?", i, key) return dbPoll(query, -1) end end end addCommandHandler("lol", function(p) for i, row in ipairs(getDBAccountData(getPlayerAccount(p), "Ranks")) do for column, value in pairs(row) do outputChatBox(column..": "..value) end end end) Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 Try. connection = dbConnect( "sqlite", "groups.db" ) function test(account, key) for i, values in ipairs(getAccounts()) do if values == account then local query = dbQuery(connection, "SELECT value FROM groups WHERE userid =? AND key =?", i, key) return dbPoll(query, -1) end end end addCommandHandler("lol", function(p) for i, row in ipairs(getDBAccountData(getPlayerAccount(p), "Ranks")) do for column, value in pairs(row) do outputChatBox(column..": "..value) end end end) Sorry, I made mistake, the function is not getDBAccountData but test so I fixed it and it's still not working. Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 What do you mean by the insert code ? Here is my code: connection = dbConnect( "sqlite", "groups.db" ) function test(account, key) for i, values in ipairs(getAccounts()) do if values == account then local query = dbQuery(connection, "SELECT value FROM groups WHERE userid =? AND key =?", i, key) return dbPoll(query, -1) end end end addCommandHandler("lol", function(p) for i, row in ipairs(test(getPlayerAccount(p), "Ranks")) do for column, value in ipairs(row) do outputChatBox(column..": "..value, root) end end end) Link to comment
TAPL Posted May 8, 2015 Share Posted May 8, 2015 The code where you've inserted the row. Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 It's coming from a script so I don't know, what about that ? CREATE TABLE `groups` ( `id` INTEGER, `userid` INTEGER, `key` TEXT, `value` TEXT, `type` INTEGER, PRIMARY KEY(id) ); Link to comment
ma2med Posted May 8, 2015 Author Share Posted May 8, 2015 Oh, I got it. Thanks WhoAmI and TAPL. 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