Maurize Posted May 3, 2012 Share Posted May 3, 2012 "Database query failed: Database is locked" - what does this mean? Before I've created another table, my sql database worked perfectly. addCommandHandler( "house", function( thePlayer, cmd, Int, Preis ) if ( getDatabase( thePlayer, "Admin" ) == 1 ) then local X1, Y1, Z1 = getElementPosition( thePlayer ) if ( Int == "1" ) then In = 5 X2 = 1298.9 Y2 = -796.4 Z2 = 1084.0 elseif ( Int == "2" ) then In = 1 X2 = 223.2 Y2 = 1287.5 Z2 = 1082.1 elseif ( Int == "3" ) then In = 5 X2 = 2233.7 Y2 = -1115.1 Z2 = 1050.9 elseif ( Int == "4" ) then In = 8 X2 = 2365.3 Y2 = -1135.6 Z2 = 1050.9 elseif ( Int == "5" ) then In = 11 X2 = 2283.0 Y2 = -1139.7 Z2 = 1050.9 elseif ( Int == "6" ) then In = 6 X2 = 2196.2 Y2 = -1204.4 Z2 = 1049.0 elseif ( Int == "7" ) then In = 10 X2 = 2269.8 Y2 = -1210.5 Z2 = 1047.6 elseif ( Int == "8" ) then In = 6 X2 = 2308.8 Y2 = -1212.8 Z2 = 1049.0 elseif ( Int == "9" ) then In = 2 X2 = 2237.5 Y2 = -1080.5 Z2 = 1049.0 elseif ( Int == "10" ) then In = 9 X2 = 2317.9 Y2 = -1026.2 Z2 = 1050.2 elseif ( Int == "11" ) then In = 5 X2 = 140.4 Y2 = 1366.6 Z2 = 1083.9 end executeSQLInsert( "HouseData", "'0', '"..Preis.."', '"..In.."', '"..X1.."', '"..Y1.."', '"..Z1.."', '"..X2.."', '"..Y2.."', '"..Z2.."'" ) createPickup( X1, Y1, Z1, 3, 1272, 2000 ) end end ) & is it possible to get all data which is in table? I'm working on housing system and need to create a pickup for every line ( 1 Line = 1 House ) addEventHandler( "onResourceStart", resourceRoot, function() executeSQLCreateTable( "HouseData", "Name STRING, Preis INT, Int INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, IntX, IntY, IntZ" ) local db = executeSQLSelect( "HouseData", "*" ) if ( db ) then createPickup( db[1]["PosX"], db[1]["PosY"], db[1]["PosZ"], 3, 1272, 2000 ) end end ) Thanks. Link to comment
Castillo Posted May 3, 2012 Share Posted May 3, 2012 Use a for loop with the query received. Link to comment
Maurize Posted May 3, 2012 Author Share Posted May 3, 2012 u mean "while" or " for i, v in pairs" ?? example please.. Link to comment
jeremaniak Posted May 3, 2012 Share Posted May 3, 2012 for k, v in ipairs do -- your shit here Link to comment
Maurize Posted May 3, 2012 Author Share Posted May 3, 2012 hm okay, but i heared in ipairs i need a specified number to get the lines which are selected.. Link to comment
Jaysds1 Posted May 4, 2012 Share Posted May 4, 2012 try this: local elementPlayer = getRootElement() addEventHandler( "onResourceStart", resourceRoot,function() executeSQLCreateTable( "HouseData", "Name STRING, Preis INT, Int INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, IntX, IntY, IntZ" ) local db = executeSQLSelect( "HouseData", "*" ) for i,v in ipairs(db)do name,preis,Int,posX,posY,posZ,IntX,IntY,IntZ = unpack(v) createPickup( posX, posY,posZ,3, 1272, 2000 ) end end ) addCommandHandler( "house",function( thePlayer, cmd, Int, Preis ) if ( getDatabase( thePlayer, "Admin" ) == 1 ) then local X1, Y1, Z1 = getElementPosition( thePlayer ) if(Int)then Int = tonumber(Int) local Interiors = { {5,1298.9,-796.4,1084.0}, {1,223.2,1287.5,1082.1}, {5,2233.7,-1115.1,1050.9}, {8,2365.3,-1135.6,1050.9}, {11,2283.0,-1139.7,1050.9}, {6,2196.2,-1204.4,1049.0}, {10,2269.8,-1210.5,1047.6}, {6,2308.8,-1212.8,1049.0}, {2,2237.5,-1080.5,1049.0}, {9,2317.9,-1026.2,1050.2}, {5,140.4,1366.6,1083.9} } local In,X2,Y2,Z2 = unpack(Interiors[Int]) end end executeSQLInsert( "HouseData", "'0', '"..Preis.."', '"..In.."', '"..X1.."', '"..Y1.."', '"..Z1.."', '"..X2.."', '"..Y2.."', '"..Z2.."'" ) createPickup( X1, Y1, Z1, 3, 1272, 2000 ) end end ) addCommandHandler( "checkH",function( thePlayer, cmd, Int ) if ( getDatabase( thePlayer, "Admin" ) == 1 ) then setElementData(thePlayer,"prePos",getElementPosition(thePlayer)) if(Int)then Int = tonumber(Int) local Interiors = { {5,1298.9,-796.4,1084.0}, {1,223.2,1287.5,1082.1}, {5,2233.7,-1115.1,1050.9}, {8,2365.3,-1135.6,1050.9}, {11,2283.0,-1139.7,1050.9}, {6,2196.2,-1204.4,1049.0}, {10,2269.8,-1210.5,1047.6}, {6,2308.8,-1212.8,1049.0}, {2,2237.5,-1080.5,1049.0}, {9,2317.9,-1026.2,1050.2}, {5,140.4,1366.6,1083.9} } local In,X2,Y2,Z2 = unpack(Interiors[Int]) setElementInterior(thePlayer,In,X2,Y2,Z2) end bindKey( thePlayer, "space", "down",out) end ) function out( player ) x,y,z = getElementData(player,"prePos") setElementInterior( player, 0, x, y, z ) unbindKey( player, "space", "down",out ) end function getDatabase( element, value ) local user = getPlayerName( element ) local db = executeSQLSelect( "HouseData", "*", "Name = '"..user.."'" ) if ( db ) and ( #db == 1 ) then local data = db[1][value] return data end end function setDatabase( element, value, data ) local user = getPlayerName( element ) local db = executeSQLSelect ( "HouseData", "*", "Name = '"..user.."'") if ( db ) and ( #db == 1 ) then executeSQLUpdate( "HouseData", value.." = '"..tostring( data ).."'", "Name = '"..user.."'" ) end end Link to comment
Castillo Posted May 4, 2012 Share Posted May 4, 2012 u mean "while" or " for i, v in pairs" ?? example please.. This: addEventHandler ( "onResourceStart", resourceRoot, function ( ) executeSQLCreateTable ( "HouseData", "Name STRING, Preis INT, Int INT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, IntX, IntY, IntZ" ) for index, row in ipairs ( executeSQLQuery ( "SELECT * FROM HouseData" ) ) do createPickup ( tonumber ( row [ "PosX" ] ), tonumber ( row [ "PosY" ] ), tonumber ( row [ "PosZ" ] ), 3, 1272, 2000 ) end end ) Link to comment
Maurize Posted May 4, 2012 Author Share Posted May 4, 2012 wow thanks alot, mates!! You are the best! And Jay, thanks for showing me a smarter and better way to work with tables:) Link to comment
Castillo Posted May 5, 2012 Share Posted May 5, 2012 wow thanks alot, mates!! You are the best! And Jay, thanks for showing me a smarter and better way to work with tables:) You're welcome. 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