TheNightRider Posted January 2, 2012 Share Posted January 2, 2012 Hello guys am working on a database script the trouble am having is a silly syntax error which I cannot seem to find the issue. The debugger tells me , is expected before DO but when I add it it says unexpected symbol near DO lol. Any idea's? PS don't say look at wikki cos I do that as a prime objective when am stuck but its not always giving me what am looking for to a certain extent. addEventHandler( "onResourceStart", resourceRoot, function( ) local server = dbConnect( "sqlite", "Storedinfo.db" ) local qh = dbQuery(server, "SELECT * FROM fuelpoints") if not dbFree ( dbQuery ( server,"CREATE TABLE IF NOT EXISTS vehicles ( fuelpointID, posX, posY, posZ, name)")) --then fuelpointID = type = ('int(10) unsigned', auto_increment = true, primary_key = true) then cancelEvent( ) return end -- local result = dbConnect( "sqlite", "Storedinfo.db" ) if result then for qh = (dbQuery (server, "SELECT * FROM fuelpoints")), do data in ipairs( result ) do local colshape = createColSphere( data.posX, data.posY, data.posZ, 2 ) setElementParent( colshape, fuelRoot ) setElementData( colshape, "name", tonumber( data.name ) or data.name ) end end end end ) Link to comment
Castillo Posted January 2, 2012 Share Posted January 2, 2012 Try this: addEventHandler( "onResourceStart", resourceRoot, function( ) local server = dbConnect( "sqlite", "Storedinfo.db" ) local qh = dbQuery(server, "SELECT * FROM fuelpoints") if not dbFree ( dbQuery ( server,"CREATE TABLE IF NOT EXISTS vehicles ( fuelpointID, posX, posY, posZ, name)")) --then fuelpointID = type = ('int(10) unsigned', auto_increment = true, primary_key = true) then cancelEvent( ) return end if qh then for index, data in ipairs(dbPoll ( qh, -1 )) do local colshape = createColSphere( data.posX, data.posY, data.posZ, 2 ) setElementParent( colshape, fuelRoot ) setElementData( colshape, "name", tonumber( data.name ) or data.name ) end end end ) Link to comment
JR10 Posted January 2, 2012 Share Posted January 2, 2012 (edited) This is so messed up. addEventHandler( "onResourceStart", resourceRoot, function( ) local server = dbConnect( "sqlite", "Storedinfo.db" ) dbExec ( server , "CREATE TABLE IF NOT EXISTS fuelpoints ( fuelpointID, posX, posY, posZ, name)") local result = dbPoll(dbQuery(server, "SELECT * FROM fuelpoints"),-1) if result and #result > 0 then for index,value pairs( result ) do local colshape = createColSphere( value.posX, value.posY, value.posZ, 2 ) --setElementParent( colshape, fuelRoot ) setElementData( colshape, "name", tonumber( value.name ) or value.name ) end end end ) You're selecting from a table that won't exist on first resource start. Your loop 'for' is wrong. fuelRoot is not defined. Edited January 2, 2012 by Guest Link to comment
TheNightRider Posted January 2, 2012 Author Share Posted January 2, 2012 checked script over and ive noticed its not creating the table to start with, so the next part of the scripts returns with no table Edit: for got to state yes it is defined local fuelRoot = createElement( "fuelpoint" ) If fuelRoot wasn't defined or set as an int as they say in VB C++ whatever it would return false but that is not the case here. Link to comment
Castillo Posted January 2, 2012 Share Posted January 2, 2012 local fuelRoot = createElement( "fuelpoint" ) addEventHandler( "onResourceStart", resourceRoot, function( ) local server = dbConnect( "sqlite", "Storedinfo.db" ) dbExec ( server , "CREATE TABLE IF NOT EXISTS fuelpoints ( fuelpointID, posX, posY, posZ, name)") local result = dbPoll(dbQuery(server, "SELECT * FROM fuelpoints"),-1) if result and #result > 0 then for index, value in pairs( result ) do -- Missing "in". local colshape = createColSphere( value.posX, value.posY, value.posZ, 2 ) setElementParent( colshape, fuelRoot ) setElementData( colshape, "name", tonumber( value.name ) or value.name ) end end end ) Link to comment
TheNightRider Posted January 2, 2012 Author Share Posted January 2, 2012 That did the trick thanks again budy Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 For some reason am getting table exspected got userdata I have no clue where ive gone wrong on this 1 lol addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS vehicles ( teleportID, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ,bInterior, bDimension )")) local result = dbQuery(key, "SELECT * FROM teleports" ) for key, value in ipairs( result ) do dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) end end ) Link to comment
Castillo Posted January 3, 2012 Share Posted January 3, 2012 addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ,bInterior, bDimension )")) local result = dbPoll(dbQuery(key, "SELECT * FROM teleports" ),-1) -- You forgot about dbPoll. for key, value in ipairs( result ) do dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) -- What is this ? end end ) Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Thank you another problem sorted I think its time for bed for me lol Link to comment
Castillo Posted January 3, 2012 Share Posted January 3, 2012 You're welcome . Good night then . Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 You create a table and then use another name in select. addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ,bInterior, bDimension )")) local result = dbPoll(dbQuery(key, "SELECT * FROM teleports" ),-1) -- You forgot about dbPoll. --[[for key, value in ipairs( result ) do dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) -- What is this ? end]] end ) The whole commented area doesn't make any sense. Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Sorry guys am still noob in many area's of LUA lol I am learning it but its taking time and a lot of practice lol Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 I'm just saying, so you can give it another look. You should try downloading some resource that uses SQLite. I also made a tutorial for the new db functions. Here. Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Okay budy but could you show me how i should do the dbPoll pls? Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 database = dbConnect ("sqlite","database.db") local queryHandler = dbQuery ( database , "SELECT * FROM table") queryHandler doesn't contain the values selected from the database. You must use dbPoll to check the progress of the executed string, and if it is ready, it will return the values. local returnedData = dbPoll ( queryHandler , -1 ) Check the wiki page for dbPoll. Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 omg this is not correct you create table with not type fields Try addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,\ aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) ) local result = dbPoll(dbQuery(key, "SELECT * FROM teleports" ),-1) -- You forgot about dbPoll. --[[for key, value in ipairs( result ) do dbQuery( value,"(teleportID, value.aX, value.aY, value.aZ, value.aInterior, value.aDimension, value.bX, value.bY, value.bZ, value.bInterior, value.bDimension)" ) -- What is this ? end]] end ) Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Ok should it be like this mate? function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ,bInterior, bDimension )")) local returnedData = dbPoll ( queryHandler , -1 ) local queryHandler = dbQuery ( key , "SELECT * FROM table") local result = dbPoll(dbQuery(key, "SELECT * FROM teleports" ),-1) Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 (edited) Kenix, you don't have to specify the types. function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbExec ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID, aX, aY, aZ, aInterior, aDimension, bX, bY, bZ,bInterior, bDimension )")) local result = dbPoll(dbQuery(key, "SELECT * FROM teleports" ),-1) Edited January 3, 2012 by Guest Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 Kenix, you don't have to specify the types. lol???? addEventHandler( "onResourceStart", resourceRoot, function( ) local key = dbConnect( "sqlite", "Storedinfo.db" ) dbFree ( dbQuery ( key, "CREATE TABLE IF NOT EXISTS teleports ( teleportID INT, aX FLOAT, aY FLOAT,\ aZ FLOAT, aInterior INT, aDimension INT, bX FLOAT, bY FLOAT, bZ FLOAT,bInterior INT, bDimension INT )" ) ) local returnedData = dbPoll ( dbQuery ( key , "SELECT * FROM table" ), -1 ) local result = dbPoll ( dbQuery( key, "SELECT * FROM teleports" ),-1 ) end ) Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 Thanks man it passes debugger hope its gonna work PS no you don't have to specify fields for it do something. Link to comment
JR10 Posted January 3, 2012 Share Posted January 3, 2012 You can just use dbExec instead of dbFree ( dbQuery. Kenix, I've tested it before, field types are optional. Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 No problem JR10,Only in function dbQuery ? Link to comment
TheNightRider Posted January 3, 2012 Author Share Posted January 3, 2012 The code you posted is full of syntax errors Link to comment
Kenix Posted January 3, 2012 Share Posted January 3, 2012 (edited) I use mysql module mysql_query Edited January 3, 2012 by Guest 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