Jump to content

[HELP]DATABSE


scolen

Recommended Posts

No purchased vehicles will be left. In the console, here is an error: "CarShop-System/Server.lua:120: dbExec failed; (1) SQL argument error
".. but the localhost is working fine without any errors, when I put it on the server it happens like this. What is the reason for that ?


createBlip ( 2131.88086, -1149.92566, 24.21433, 55, 2, 0, 0, 0, 255, 0, 99999.0, getRootElement( ) )
local vehDB = dbConnect( 'sqlite', 'Loja de veiculos - Database.db' )
dbExec( vehDB, ' CREATE TABLE IF NOT EXISTS `VehiclesSystem_Players` (pSerial, vehID, vehName, vehPrice, Subscription) ' )
--dbExec( vehDB, ' DROP TABLE `VehiclesSystem_Players` ' )

vehPers = {  };
vehview = {  };

function refreshMyList(  )
	local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` ' )
		local results = dbPoll( check, -1 )
		if ( type( results ) == 'table' and #results == 0 or not results ) then triggerClientEvent( root, 'VehiclesSystem;emptyMyList', root ) return end
	triggerClientEvent( root, 'VehiclesSystem;putMyVehicles', root, results )
end
addEvent( 'refreshMyListS', true ) addEventHandler( 'refreshMyListS', root, refreshMyList )

function viewVehiclex( ID, x, y, z, state )
	if ( state == 'close' ) then
	if ( isElement( vehview[source] ) ) then destroyElement( vehview[source] ) end
	elseif ( state == 'view' ) then
	if ( isElement( vehview[source] ) ) then if ( getElementModel( vehview[source] ) ) == ID then return end destroyElement( vehview[source] ) end
	vehview[source] = createVehicle( ID, x, y, z + 0.2, 0, 0, 10 )
	setElementDimension( vehview[source], getElementData( root, 'vehiclesSystem;dimension' ) or 1 )
	setElementDimension( source, getElementData( root, 'vehiclesSystem;dimension' ) or 1 )
	setElementData( root, 'vehiclesSystem;dimension', getElementData( root, 'vehiclesSystem;dimension' ) + 1 or 1 )
end
end
addEvent( 'VehiclesSystem;createViewVehicle', true )
addEventHandler( 'VehiclesSystem;createViewVehicle', root, viewVehiclex )

addEvent( 'VehiclesSystem;destroyPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;destroyPersonalVehicle', root,
function(  )
	if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end
end )

addEvent( 'VehiclesSystem;createRentVehicle', true )
addEventHandler( 'VehiclesSystem;createRentVehicle', root,
function( ID, vehName )
	if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end
	vehPers[source] = createVehicle( ID, 2126.08862, -1136.05115, 25.47241 + 1, -0, 0, 224.5189666748 )
	fadeCamera( source, false )
		setTimer( fadeCamera, 1500, 1, source, true )
	takePlayerMoney( source, 1000 )
	setElementDimension( vehPers[source], 0 )
	setElementDimension( source, 0 )
	setTimer( warpPedIntoVehicle, 1500, 1, source, vehPers[source] )
	setTimer( destroyElement, 300000, 1, vehPers[source] )
	setTimer( function(  )
		outputChatBox( '#1E90FF[Car Shop] #FFFFFFWarning: Your rental time is up and your vehicle has been removed #FF0000!', source, 255, 255, 255, true )
	end, 300000, 1 )
	triggerClientEvent( source, 'VehiclesSystem;gridListAddRent', source, ID, vehName )
end )

addEvent( 'VehiclesSystem;lock/unlockPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;lock/unlockPersonalVehicle', root,
function(  )
	if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end
		if ( isVehicleLocked( vehPers[source] ) == true ) then
			setVehicleLocked( vehPers[source], false ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSuccess, Your vehicle has been unlocked #2BFF00!', source, 255, 255, 255, true )
		else
		setVehicleLocked( vehPers[source], true ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSuccess, Your vehicle has been locked #2BFF00!', source, 255, 255, 255, true )
	end
end )

addEvent( 'VehiclesSystem;off/onPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;off/onPersonalVehicle', root,
function(  )
	if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end
		if ( getVehicleEngineState( vehPers[source] ) == true ) then
			setVehicleEngineState( vehPers[source], false ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFEngine off #2BFF00!', source, 255, 255, 255, true )
		else
		setVehicleEngineState( vehPers[source], true ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFEngine on #2BFF00!', source, 255, 255, 255, true )
	end
end )

addEvent( 'VehiclesSystem;off/onLightsPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;off/onLightsPersonalVehicle', root,
function(  )
	if ( not isElement( vehPers[source] ) ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: you dont have this vehicle #FF0000!', source, 255, 255, 255, true ) return end
		if ( getVehicleLightState( vehPers[source], 0 ) == 0 and getVehicleLightState( vehPers[source], 1 ) == 0 ) then
			setVehicleLightState( vehPers[source], 0, 1 ) setVehicleLightState( vehPers[source], 1, 1 ) setVehicleLightState( vehPers[source], 2, 1 ) setVehicleLightState( vehPers[source], 3, 1 ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFlights off #2BFF00!', source, 255, 255, 255, true )
		else
		setVehicleLightState( vehPers[source], 0, 0 ) setVehicleLightState( vehPers[source], 1, 0 ) setVehicleLightState( vehPers[source], 2, 0 ) setVehicleLightState( vehPers[source], 3, 0 ) outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFLights on #2BFF00!', source, 255, 255, 255, true )
	end
end )

addEvent( 'VehiclesSystem;sellMyPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;sellMyPersonalVehicle', root,
function( ID, price )
local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehID = ? ', getPlayerSerial( source ), ID )
		local results = dbPoll( check, -1 )
			if ( type( results ) == 'table' and #results == 0 or not results ) then outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: This vehicle is not permanent, you cannot sell it #FF0000!', source, 255, 255, 255, true ) return end
	if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end
		dbExec( vehDB, ' DELETE FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehID = ? ', getPlayerSerial( source ), ID )
			refreshMyList(  )
		givePlayerMoney( source, price )
	outputChatBox( '#2BFF00*#1E90FF[Car Shop] #FFFFFFSold! You have successfully sold your vehicle #2BFF00!', source, 255, 255, 255, true )
end )

addEvent( 'VehiclesSystem;createPersonalVehicle', true )
addEventHandler( 'VehiclesSystem;createPersonalVehicle', root,
function( ID )
	local x, y, z = getElementPosition( source )
		if ( isElement( vehPers[source] ) ) then destroyElement( vehPers[source] ) end
			vehPers[source] = createVehicle( ID, x + 2, y + 2, z + 1 )
			if ( getElementData( source, 'VehiclesSystem;WarpToVehicle' ) == 'Enabled' ) then
		warpPedIntoVehicle( source, vehPers[source] )
		setElementData( vehPers[source], 'myPersVehicle', getPlayerName( source ) )
	end
end )

addEvent( 'VehiclesSystem;buyCurrentCar', true )
addEventHandler( 'VehiclesSystem;buyCurrentCar', root,
function( ID, Name, Price )
	local check = dbQuery( vehDB, ' SELECT * FROM `VehiclesSystem_Players` WHERE pSerial = ? AND vehddID = ? ', getPlayerSerial( source ), ID )
		local results = dbPoll( check, -1 )
			if ( type( results ) == 'table' and #results == 0 or not results ) then
				dbExec( vehDB, ' INSERT INTO `VehiclesSystem_Players` VALUES(?,?,?,?,?) ', getPlayerSerial( source ), tonumber(ID), Name, Price, 'Permanente' )
					vehPers[source] = createVehicle( ID, 2126.08862, -1136.05115, 25.47241 + 1, -0, 0, 224.5189666748 )
						warpPedIntoVehicle( source, vehPers[source] )
						takePlayerMoney( source, Price )
					setTimer(setCameraTarget, 1500, 1, source )
					setElementDimension( vehPers[source], 0 )
					setElementDimension( source, 0 )
					fadeCamera( source, false )
					setTimer( fadeCamera, 1500, 1, source, true )
				triggerClientEvent( source, 'VehiclesSystem;hideBuyWindow', source )
			viewVehiclex( nil, nil, nil, nil, 'close' )
		refreshMyList(  )
	else outputChatBox( '#1E90FF[Car Shop] #FFFFFFError: This vehicle already exists in your list #FF0000!', source, 255, 255, 255, true ) return end
end )

 

Edited by scolen
Link to comment
  • Moderators
5 hours ago, scolen said:

What is the reason for that ?

You might consider using another filename. Also stopping the resource on onResourceStart is a good way for error handling, since this resource is not very useful without a databasse.

 

addEventHandler ( "onResourceStart", resourceRoot, 
function ()   
	vehDB = dbConnect( 'sqlite', 'veiculosdatabase.db' )
	if not vehDB then
		return cancelEvent (true, "Unable to connect to database.")
	end
	dbExec( vehDB, ' CREATE TABLE IF NOT EXISTS `VehiclesSystem_Players` (pSerial, vehID, vehName, vehPrice, Subscription) ' )
end, false)

 

 

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