fivosga Posted April 21, 2012 Share Posted April 21, 2012 I managed to edit community top times and make them quite nice and now I want to make a MY-SQL share with another clan. The problem is that the community top times are exporting in SQLite... How can I make them export in MY-SQL? This is the code of the SQLite database -- -- databasetable_server.lua -- -- A Lua table which is loaded/saved from the sqlite database -- Handled column types are TEXT and REAL -- SDatabaseTable = {} SDatabaseTable.__index = SDatabaseTable SDatabaseTable.instances = {} --------------------------------------------------------------------------- -- -- SDatabaseTable:create() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:create(name,columns,columnTypes) local id = #SDatabaseTable.instances + 1 SDatabaseTable.instances[id] = setmetatable( { id = id, name = name, columns = columns, columnTypes = columnTypes, rows = {}, }, self ) SDatabaseTable.instances[id]:postCreate() return SDatabaseTable.instances[id] end --------------------------------------------------------------------------- -- -- SDatabaseTable:destroy() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:destroy() SDatabaseTable.instances[self.id] = nil self.id = 0 ped = nil vehicle = nil end --------------------------------------------------------------------------- -- -- SDatabaseTable:postCreate() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:postCreate() -- Set column types as strings if not set while #self.columnTypes < #self.columns do table.insert( self.columnTypes, 'TEXT' ) end end --------------------------------------------------------------------------- -- -- SDatabaseTable:safestring() -- -- -- --------------------------------------------------------------------------- function safestring( s ) -- escape ' return s:gsub( "(['])", "''" ) end function qsafestring( s ) -- ensure is wrapped in ' return "'" .. safestring(s) .. "'" end function qsafetablename( s ) return qsafestring(s) end --------------------------------------------------------------------------- -- -- SDatabaseTable:load() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:load() for i=1,10 do if self:tryLoad() then return end end end --------------------------------------------------------------------------- -- -- SDatabaseTable:tryLoad() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:tryLoad() outputDebug( 'TOPTIMES', 'SDatabaseTable: Loading ' .. self.name ) self.rows = {} local cmd -- CREATE TABLE self:createTable() -- SELECT -- Build command cmd = 'SELECT * FROM ' .. qsafetablename( self.name ) local sqlResults = executeSQLQuery( cmd ) if not sqlResults then return false end -- Process into rows self.rows = {} for r,sqlRow in ipairs(sqlResults) do local row = {} for c,column in ipairs(self.columns) do row[column] = sqlRow[column] end table.insert( self.rows, row ) end -- Make copy to detect changes self.rowsCopy = table.deepcopy(self.rows) return true end --------------------------------------------------------------------------- -- -- SDatabaseTable:save() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:save() -- See if save required local bChanged = false if not self.rowsCopy or #self.rows ~= #self.rowsCopy then bChanged = true else for r,row in ipairs(self.rows) do for c,col in ipairs(self.columns) do if self.rows[r][col] ~= self.rowsCopy[r][col] then bChanged = true break end end if bChanged then break end end end if not bChanged then return end outputDebug( 'TOPTIMES', 'SDatabaseTable: Saving ' .. self.name ) -- Being save executeSQLQuery( 'BEGIN TRANSACTION' ); local cmd -- DELETE TABLE -- Build command --cmd = 'DELETE FROM ' .. qsafetablename( self.name ) cmd = 'DROP TABLE IF EXISTS ' .. qsafetablename( self.name ) executeSQLQuery( cmd ) -- CREATE TABLE self:createTable() -- Rebuild -- For each row for r,row in ipairs(self.rows) do -- INSERT INTO cmd = 'INSERT INTO ' .. qsafetablename( self.name ) .. ' VALUES (' for c=1,#self.columns do if c > 1 then cmd = cmd .. ', ' end local key = self.columns[c] if type(row[key]) == 'number' then cmd = cmd .. row[key] or 0 else cmd = cmd .. qsafestring( row[key] or '' ) end end cmd = cmd .. ')' executeSQLQuery( cmd ) end executeSQLQuery( 'END TRANSACTION' ); -- Make copy to detect changes self.rowsCopy = table.deepcopy(self.rows) end --------------------------------------------------------------------------- -- -- SDatabaseTable:createTable() -- -- -- --------------------------------------------------------------------------- function SDatabaseTable:createTable() local cmd -- CREATE TABLE -- Build command cmd = 'CREATE TABLE IF NOT EXISTS ' .. qsafetablename( self.name ) .. ' (' for c=1,#self.columns do if c > 1 then cmd = cmd .. Link to comment
Castillo Posted April 21, 2012 Share Posted April 21, 2012 Learn Lua and MySQL and you'll be able to do it. Link to comment
Michael# Posted April 22, 2012 Share Posted April 22, 2012 Learn Lua and MySQL and you'll be able to do it. I said him the same, he don't want to learn Lua. @@fivosga, as Solidsnake14 said, you must LEARN to do it, we will not do it for you. Link to comment
meh Posted April 22, 2012 Share Posted April 22, 2012 you must LEARN to do it, we will not do it for you. haha, i see this is the most popular answer in the scripting section these days. where may i suggest to rename the section to "we will not do it for you"? Link to comment
Absence2 Posted April 22, 2012 Share Posted April 22, 2012 why don't you grow up? It's common sense and this is the real world, do it yourself or learn, simple as that. However if you need help, you'll get help throughtout the proccess. I'm a Graphics Designer too. I don't remember when fellow designers worked for free when they easily could get paid, plus when it could take hours to finish the work (Proffessional designers), any new designer will most likely help in order to gain experience tho. if you don't like what the real life has to offer, go play in candy land, because this IS the real life. And last time I checked this scripting section was never and isn't called REQUEST SCRIPTS FOR FREE. like the third time you provoke people here because they refuse to SCRIPT for someone or most likely you. You'll get nowhere with this attitude. Link to comment
meh Posted April 22, 2012 Share Posted April 22, 2012 whoa, man. ur so mature. you can count lousy and (claim to) know so much about this life. i'm jealous. can i take classes from you or something? Link to comment
Aibo Posted April 22, 2012 Share Posted April 22, 2012 you must LEARN to do it, we will not do it for you. haha, i see this is the most popular answer in the scripting section these days. where may i suggest to rename the section to "we will not do it for you"? actually, "we will not do it for you" is a pretty legit name. because we won't. this section is for questions/problems/support, not requests. meh, if you wanna go personal — do it via PM. Link to comment
fivosga Posted April 22, 2012 Author Share Posted April 22, 2012 ok! I will try to learn although I will totaly fail on it! Can you at least tell me what the problem is on DrakeN's version? Link to comment
Michael# Posted April 22, 2012 Share Posted April 22, 2012 Debug, check MySQL settings, check if MySQL module is working properly. 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