Jump to content

Syntax error


Recommended Posts

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

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

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 by Guest
Link to comment

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

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

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

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

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

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 by Guest
Link to comment
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

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