Advertisement
Shiny_

Untitled

Jun 27th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.69 KB | None | 0 0
  1. local Connection    = dbConnect("sqlite", "sqlite.db")
  2. local TABELA        = "TABELA"
  3. local HandleQuery   = dbQuery(Connection, "CREATE TABLE IF NOT EXISTS " .. TABELA .. " (Tekst TEXT, ID INTEGER)")
  4. local Handler_DB    = nil
  5. local Number        = 250000
  6.  
  7. local MySQL_HOST  = "46.4.177.235"
  8. local MySQL_USER  = "Linux_Shines"
  9. local MySQL_PASS  = "test"
  10. local MySQL_DB    = "Linux_Shines"
  11. local MySQL_PORT  = 3306
  12.  
  13. addEventHandler("onResourceStart", resourceRoot, function()
  14.     MySQLConnection = dbConnect("mysql", "dbname=" .. MySQL_DB .. ";host=" .. MySQL_HOST, MySQL_USER, MySQL_PASS, "share=1", "port=" .. MySQL_PORT)
  15.     MySQLQuery = dbQuery(MySQLConnection, "CREATE TABLE IF NOT EXISTS Test (Kolumna_1 TEXT, Kolumna_2 INT(2), Kolumna_3 TEXT);")
  16.     local NOW = getTickCount()
  17.     for i = 0, Number do
  18.         print()
  19.     end
  20.     local TIME__ = getTickCount() - NOW
  21.     outputDebugString("Czas wykonania pętli - " .. TIME__ .. " milisekund.", 3)
  22.    
  23.     if not Connection then
  24.         outputDebugString("Brak połączenia z bazą danych.", 1)
  25.     else
  26.         outputDebugString("Połączono z bazą danych.", 3)
  27.         Fill_Table()
  28.         Show_Table()
  29.     end
  30. end)
  31.  
  32. function Fill_Table()
  33.     local NOW = getTickCount()
  34.     for i = 0, Number do
  35.         SQLite_Query = dbQuery(Connection, "INSERT INTO " .. TABELA .. " (Tekst, ID) VALUES (?, ?)", "Tekst nr" .. i, i)
  36.     end
  37.     local Difference = getTickCount() - NOW
  38.     outputDebugString("Pomyślnie wypełniono tabelę w SQLite. Czas trwania to " .. Difference .. " milisekund", 3)
  39.  
  40.     local NOW__ = getTickCount()
  41.     for i__ = 0, Number do
  42.         MySQL_Query = dbQuery(Connection, "INSERT INTO " .. TABELA .. " (Tekst, ID) VALUES (?, ?)", "Tekst nr" .. i__, i__)
  43.     end
  44.     local Difference__ = getTickCount() - NOW__
  45.     outputDebugString("Pomyślnie wypełniono tabelę w MySQL. Czas trwania to " .. Difference__ .. " milisekund", 3)
  46. end
  47.  
  48. function Show_Table()
  49.     local NOW = getTickCount()
  50.     local QUERY__ = dbQuery(Connection, "SELECT ID FROM " .. TABELA .. " WHERE ID > 0 AND ID < 100")
  51.     local Result = dbPoll(QUERY__, -1)
  52.     local Difference = getTickCount() - NOW
  53.     outputDebugString("Pomyślnie wybrano z tabeli. Czas trwania dla SQLite to " .. Difference .. " milisekund", 3)
  54.    
  55.     local NOW__ = getTickCount()
  56.     local QUERY____ = dbQuery(Connection, "SELECT ID FROM " .. TABELA .. " WHERE ID > 0 AND ID < 100")
  57.     local Result = dbPoll(QUERY____, -1)
  58.     local Difference__ = getTickCount() - NOW__
  59.     outputDebugString("Pomyślnie wybrano z tabeli. Czas trwania dla MySQL to " .. Difference__ .. " milisekund", 3)
  60. end
  61.  
  62. addCommandHandler("insert", Fill_Table)
  63. addCommandHandler("show", Show_Table)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement