{"action":"created","comment":{"url":"https://api.github.com/repos/FPtje/MySQLite/pulls/comments/38639123","id":38639123,"diff_hunk":"@@ -171,74 +167,119 @@ local queuedQueries\n local cachedQueries\n \n function isMySQL()\n-\treturn CONNECTED_TO_MYSQL\n+    return CONNECTED_TO_MYSQL\n end\n \n function begin()\n-\tif not CONNECTED_TO_MYSQL then\n-\t\tsql.Begin()\n-\telse\n-\t\tif queuedQueries then\n-\t\t\tdebug.Trace()\n-\t\t\terror(\"Transaction ongoing!\")\n-\t\tend\n-\t\tqueuedQueries = {}\n-\tend\n+    if not CONNECTED_TO_MYSQL then\n+        sql.Begin()\n+    else\n+        if queuedQueries then\n+            debug.Trace()\n+            error(\"Transaction ongoing!\")\n+        end\n+        queuedQueries = {}\n+    end\n end\n \n function commit(onFinished)\n-\tif not CONNECTED_TO_MYSQL then\n-\t\tsql.Commit()\n-\t\tif onFinished then onFinished() end\n-\t\treturn\n-\tend\n-\n-\tif not queuedQueries then\n-\t\terror(\"No queued queries! Call begin() first!\")\n-\tend\n-\n-\tif #queuedQueries == 0 then\n-\t\tqueuedQueries = nil\n-\t\treturn\n-\tend\n-\n-\t-- Copy the table so other scripts can create their own queue\n-\tlocal queue = table.Copy(queuedQueries)\n-\tqueuedQueries = nil\n-\n-\t-- Handle queued queries in order\n-\tlocal queuePos = 0\n-\tlocal call\n-\n-\t-- Recursion invariant: queuePos > 0 and queue[queuePos] <= #queue\n-\tcall = function(...)\n-\t\tqueuePos = queuePos + 1\n-\n-\t\tif queue[queuePos].callback then\n-\t\t\tqueue[queuePos].callback(...)\n-\t\tend\n-\n-\t\t-- Base case, end of the queue\n-\t\tif queuePos + 1 > #queue then\n-\t\t\tif onFinished then onFinished() end -- All queries have finished\n-\t\t\treturn\n-\t\tend\n-\n-\t\t-- Recursion\n-\t\tlocal nextQuery = queue[queuePos + 1]\n-\t\tquery(nextQuery.query, call, nextQuery.onError)\n-\tend\n-\n-\tquery(queue[1].query, call, queue[1].onError)\n+    if not CONNECTED_TO_MYSQL then\n+        sql.Commit()\n+        if onFinished then onFinished() end\n+        return\n+    end\n+\n+    if not queuedQueries then\n+        error(\"No queued queries! Call begin() first!\")\n+    end\n+\n+    if #queuedQueries == 0 then\n+        queuedQueries = nil\n+        return\n+    end\n+\n+    -- Copy the table so other scripts can create their own queue\n+    local queue = table.Copy(queuedQueries)\n+    queuedQueries = nil\n+\n+    -- Handle queued queries in order\n+    local queuePos = 0\n+    local call\n+\n+    -- Recursion invariant: queuePos > 0 and queue[queuePos] <= #queue\n+    call = function(...)\n+        queuePos = queuePos + 1\n+\n+        if queue[queuePos].callback then\n+            queue[queuePos].callback(...)\n+        end\n+\n+        -- Base case, end of the queue\n+        if queuePos + 1 > #queue then\n+            if onFinished then onFinished() end -- All queries have finished\n+            return\n+        end\n+\n+        -- Recursion\n+        local nextQuery = queue[queuePos + 1]\n+        query(nextQuery.query, call, nextQuery.onError)\n+    end\n+\n+    query(queue[1].query, call, queue[1].onError)\n+end\n+\n+format = {}\n+function format.insert(id,tab)\n+    local VALUES_str = \"\"\n+    local VALUES = \"\"\n+\n+    local start = false\n+    for k,v in pairs(tab) do\n+        if start then --There are already vars\n+            VALUES_str = VALUES_str .. string.format(\",`%s`\", k)\n+\t\t\tVALUES = VALUES .. \",\" .. SQLStr(v)","path":"mysqlite.lua","position":169,"original_position":169,"commit_id":"2e1661c620d9d985d636f34282bfa213ed1d26bc","original_commit_id":"2e1661c620d9d985d636f34282bfa213ed1d26bc","user":{"login":"Bo98","id":1190754,"avatar_url":"https://avatars.githubusercontent.com/u/1190754?v=3","gravatar_id":"","url":"https://api.github.com/users/Bo98","html_url":"https://github.com/Bo98","followers_url":"https://api.github.com/users/Bo98/followers","following_url":"https://api.github.com/users/Bo98/following{/other_user}","gists_url":"https://api.github.com/users/Bo98/gists{/gist_id}","starred_url":"https://api.github.com/users/Bo98/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bo98/subscriptions","organizations_url":"https://api.github.com/users/Bo98/orgs","repos_url":"https://api.github.com/users/Bo98/repos","events_url":"https://api.github.com/users/Bo98/events{/privacy}","received_events_url":"https://api.github.com/users/Bo98/received_events","type":"User","site_admin":false},"body":"Tabs are being used here.","created_at":"2015-09-03T12:19:26Z","updated_at":"2015-09-03T12:19:26Z","html_url":"https://github.com/FPtje/MySQLite/pull/3#discussion_r38639123","pull_request_url":"https://api.github.com/repos/FPtje/MySQLite/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/comments/38639123"},"html":{"href":"https://github.com/FPtje/MySQLite/pull/3#discussion_r38639123"},"pull_request":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/FPtje/MySQLite/pulls/3","id":44085587,"html_url":"https://github.com/FPtje/MySQLite/pull/3","diff_url":"https://github.com/FPtje/MySQLite/pull/3.diff","patch_url":"https://github.com/FPtje/MySQLite/pull/3.patch","issue_url":"https://api.github.com/repos/FPtje/MySQLite/issues/3","number":3,"state":"open","locked":false,"title":"Updated MySQLite","user":{"login":"00875","id":6339511,"avatar_url":"https://avatars.githubusercontent.com/u/6339511?v=3","gravatar_id":"","url":"https://api.github.com/users/00875","html_url":"https://github.com/00875","followers_url":"https://api.github.com/users/00875/followers","following_url":"https://api.github.com/users/00875/following{/other_user}","gists_url":"https://api.github.com/users/00875/gists{/gist_id}","starred_url":"https://api.github.com/users/00875/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/00875/subscriptions","organizations_url":"https://api.github.com/users/00875/orgs","repos_url":"https://api.github.com/users/00875/repos","events_url":"https://api.github.com/users/00875/events{/privacy}","received_events_url":"https://api.github.com/users/00875/received_events","type":"User","site_admin":false},"body":"Added format.insert and format.update for easier operations.\r\ntimer.Exists is excess.\r\nDestroy -> Remove\r\nChanged tabs to spaces.\r\nUsing TMySQL4 by default.\r\n\r\nFirst of all, i added helpers, what can turn this\r\n![2015-09-03_16-21_garry s mod](https://cloud.githubusercontent.com/assets/6339511/9654911/051f973a-5258-11e5-9bfa-ac3479d56ac9.jpg)\r\nSecond, i changed all tabs to spaces (what you want)\r\n\r\nAnd for the end, i forced to use TMySQL4 by default. Why?\r\nMySQLOO has VERY poor prefomance.\r\nWhen running many queries at once, server will be lagging before all queries is finished.\r\nWhen using InnoDB and innodb_flush_log_at_trx_commit = 1 server will be locked up before query is finished (many quieries at once (not so much, about 90-150) can cause server locked up permanently)\r\n\r\nTest results:\r\n100 queries, TMySQL4 and MySQLOO no lag.\r\n1000 queries, TMySQL4 server lag for 100 ms, MySQLOO server lag for 1,2 seconds.\r\n10000 queries, TMySQL server lag for 207 ms, MySQLOO server lag for 3 seconds, and server was lagging for about 20 seconds before queries is finished.\r\n100000 queries, TMySQL4 server lag for 616 ms, MySQLOO server lag for 10!!! seconds, and server was lagging more than 2 minutes.\r\nIn all test before running queries table was truncated.\r\nIn all test used this query ``` INSERT INTO test (id,text) VALUES (NULL,'example'); ```","created_at":"2015-09-03T09:29:28Z","updated_at":"2015-09-03T12:19:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a0e7c18e1c575885b02faac61f7036dbe2aec4bc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FPtje/MySQLite/pulls/3/commits","review_comments_url":"https://api.github.com/repos/FPtje/MySQLite/pulls/3/comments","review_comment_url":"https://api.github.com/repos/FPtje/MySQLite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FPtje/MySQLite/issues/3/comments","statuses_url":"https://api.github.com/repos/FPtje/MySQLite/statuses/2e1661c620d9d985d636f34282bfa213ed1d26bc","head":{"label":"00875:helpers","ref":"helpers","sha":"2e1661c620d9d985d636f34282bfa213ed1d26bc","user":{"login":"00875","id":6339511,"avatar_url":"https://avatars.githubusercontent.com/u/6339511?v=3","gravatar_id":"","url":"https://api.github.com/users/00875","html_url":"https://github.com/00875","followers_url":"https://api.github.com/users/00875/followers","following_url":"https://api.github.com/users/00875/following{/other_user}","gists_url":"https://api.github.com/users/00875/gists{/gist_id}","starred_url":"https://api.github.com/users/00875/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/00875/subscriptions","organizations_url":"https://api.github.com/users/00875/orgs","repos_url":"https://api.github.com/users/00875/repos","events_url":"https://api.github.com/users/00875/events{/privacy}","received_events_url":"https://api.github.com/users/00875/received_events","type":"User","site_admin":false},"repo":{"id":41849092,"name":"MySQLite","full_name":"00875/MySQLite","owner":{"login":"00875","id":6339511,"avatar_url":"https://avatars.githubusercontent.com/u/6339511?v=3","gravatar_id":"","url":"https://api.github.com/users/00875","html_url":"https://github.com/00875","followers_url":"https://api.github.com/users/00875/followers","following_url":"https://api.github.com/users/00875/following{/other_user}","gists_url":"https://api.github.com/users/00875/gists{/gist_id}","starred_url":"https://api.github.com/users/00875/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/00875/subscriptions","organizations_url":"https://api.github.com/users/00875/orgs","repos_url":"https://api.github.com/users/00875/repos","events_url":"https://api.github.com/users/00875/events{/privacy}","received_events_url":"https://api.github.com/users/00875/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/00875/MySQLite","description":"Lua module for Garry's mod. Depends on MySQLOO.","fork":true,"url":"https://api.github.com/repos/00875/MySQLite","forks_url":"https://api.github.com/repos/00875/MySQLite/forks","keys_url":"https://api.github.com/repos/00875/MySQLite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/00875/MySQLite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/00875/MySQLite/teams","hooks_url":"https://api.github.com/repos/00875/MySQLite/hooks","issue_events_url":"https://api.github.com/repos/00875/MySQLite/issues/events{/number}","events_url":"https://api.github.com/repos/00875/MySQLite/events","assignees_url":"https://api.github.com/repos/00875/MySQLite/assignees{/user}","branches_url":"https://api.github.com/repos/00875/MySQLite/branches{/branch}","tags_url":"https://api.github.com/repos/00875/MySQLite/tags","blobs_url":"https://api.github.com/repos/00875/MySQLite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/00875/MySQLite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/00875/MySQLite/git/refs{/sha}","trees_url":"https://api.github.com/repos/00875/MySQLite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/00875/MySQLite/statuses/{sha}","languages_url":"https://api.github.com/repos/00875/MySQLite/languages","stargazers_url":"https://api.github.com/repos/00875/MySQLite/stargazers","contributors_url":"https://api.github.com/repos/00875/MySQLite/contributors","subscribers_url":"https://api.github.com/repos/00875/MySQLite/subscribers","subscription_url":"https://api.github.com/repos/00875/MySQLite/subscription","commits_url":"https://api.github.com/repos/00875/MySQLite/commits{/sha}","git_commits_url":"https://api.github.com/repos/00875/MySQLite/git/commits{/sha}","comments_url":"https://api.github.com/repos/00875/MySQLite/comments{/number}","issue_comment_url":"https://api.github.com/repos/00875/MySQLite/issues/comments{/number}","contents_url":"https://api.github.com/repos/00875/MySQLite/contents/{+path}","compare_url":"https://api.github.com/repos/00875/MySQLite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/00875/MySQLite/merges","archive_url":"https://api.github.com/repos/00875/MySQLite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/00875/MySQLite/downloads","issues_url":"https://api.github.com/repos/00875/MySQLite/issues{/number}","pulls_url":"https://api.github.com/repos/00875/MySQLite/pulls{/number}","milestones_url":"https://api.github.com/repos/00875/MySQLite/milestones{/number}","notifications_url":"https://api.github.com/repos/00875/MySQLite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/00875/MySQLite/labels{/name}","releases_url":"https://api.github.com/repos/00875/MySQLite/releases{/id}","created_at":"2015-09-03T08:21:16Z","updated_at":"2015-09-03T08:21:16Z","pushed_at":"2015-09-03T09:36:48Z","git_url":"git://github.com/00875/MySQLite.git","ssh_url":"git@github.com:00875/MySQLite.git","clone_url":"https://github.com/00875/MySQLite.git","svn_url":"https://github.com/00875/MySQLite","homepage":null,"size":92,"stargazers_count":0,"watchers_count":0,"language":"Lua","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"FPtje:master","ref":"master","sha":"aabb9e3a55ff151ef52560af960f0638f81b995e","user":{"login":"FPtje","id":1202014,"avatar_url":"https://avatars.githubusercontent.com/u/1202014?v=3","gravatar_id":"","url":"https://api.github.com/users/FPtje","html_url":"https://github.com/FPtje","followers_url":"https://api.github.com/users/FPtje/followers","following_url":"https://api.github.com/users/FPtje/following{/other_user}","gists_url":"https://api.github.com/users/FPtje/gists{/gist_id}","starred_url":"https://api.github.com/users/FPtje/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FPtje/subscriptions","organizations_url":"https://api.github.com/users/FPtje/orgs","repos_url":"https://api.github.com/users/FPtje/repos","events_url":"https://api.github.com/users/FPtje/events{/privacy}","received_events_url":"https://api.github.com/users/FPtje/received_events","type":"User","site_admin":false},"repo":{"id":16412408,"name":"MySQLite","full_name":"FPtje/MySQLite","owner":{"login":"FPtje","id":1202014,"avatar_url":"https://avatars.githubusercontent.com/u/1202014?v=3","gravatar_id":"","url":"https://api.github.com/users/FPtje","html_url":"https://github.com/FPtje","followers_url":"https://api.github.com/users/FPtje/followers","following_url":"https://api.github.com/users/FPtje/following{/other_user}","gists_url":"https://api.github.com/users/FPtje/gists{/gist_id}","starred_url":"https://api.github.com/users/FPtje/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FPtje/subscriptions","organizations_url":"https://api.github.com/users/FPtje/orgs","repos_url":"https://api.github.com/users/FPtje/repos","events_url":"https://api.github.com/users/FPtje/events{/privacy}","received_events_url":"https://api.github.com/users/FPtje/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/FPtje/MySQLite","description":"Lua module for Garry's mod. Depends on MySQLOO.","fork":false,"url":"https://api.github.com/repos/FPtje/MySQLite","forks_url":"https://api.github.com/repos/FPtje/MySQLite/forks","keys_url":"https://api.github.com/repos/FPtje/MySQLite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FPtje/MySQLite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FPtje/MySQLite/teams","hooks_url":"https://api.github.com/repos/FPtje/MySQLite/hooks","issue_events_url":"https://api.github.com/repos/FPtje/MySQLite/issues/events{/number}","events_url":"https://api.github.com/repos/FPtje/MySQLite/events","assignees_url":"https://api.github.com/repos/FPtje/MySQLite/assignees{/user}","branches_url":"https://api.github.com/repos/FPtje/MySQLite/branches{/branch}","tags_url":"https://api.github.com/repos/FPtje/MySQLite/tags","blobs_url":"https://api.github.com/repos/FPtje/MySQLite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FPtje/MySQLite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FPtje/MySQLite/git/refs{/sha}","trees_url":"https://api.github.com/repos/FPtje/MySQLite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FPtje/MySQLite/statuses/{sha}","languages_url":"https://api.github.com/repos/FPtje/MySQLite/languages","stargazers_url":"https://api.github.com/repos/FPtje/MySQLite/stargazers","contributors_url":"https://api.github.com/repos/FPtje/MySQLite/contributors","subscribers_url":"https://api.github.com/repos/FPtje/MySQLite/subscribers","subscription_url":"https://api.github.com/repos/FPtje/MySQLite/subscription","commits_url":"https://api.github.com/repos/FPtje/MySQLite/commits{/sha}","git_commits_url":"https://api.github.com/repos/FPtje/MySQLite/git/commits{/sha}","comments_url":"https://api.github.com/repos/FPtje/MySQLite/comments{/number}","issue_comment_url":"https://api.github.com/repos/FPtje/MySQLite/issues/comments{/number}","contents_url":"https://api.github.com/repos/FPtje/MySQLite/contents/{+path}","compare_url":"https://api.github.com/repos/FPtje/MySQLite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FPtje/MySQLite/merges","archive_url":"https://api.github.com/repos/FPtje/MySQLite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FPtje/MySQLite/downloads","issues_url":"https://api.github.com/repos/FPtje/MySQLite/issues{/number}","pulls_url":"https://api.github.com/repos/FPtje/MySQLite/pulls{/number}","milestones_url":"https://api.github.com/repos/FPtje/MySQLite/milestones{/number}","notifications_url":"https://api.github.com/repos/FPtje/MySQLite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FPtje/MySQLite/labels{/name}","releases_url":"https://api.github.com/repos/FPtje/MySQLite/releases{/id}","created_at":"2014-01-31T15:51:35Z","updated_at":"2015-07-14T05:17:25Z","pushed_at":"2015-09-03T09:36:48Z","git_url":"git://github.com/FPtje/MySQLite.git","ssh_url":"git@github.com:FPtje/MySQLite.git","clone_url":"https://github.com/FPtje/MySQLite.git","svn_url":"https://github.com/FPtje/MySQLite","homepage":null,"size":182,"stargazers_count":8,"watchers_count":8,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/3"},"html":{"href":"https://github.com/FPtje/MySQLite/pull/3"},"issue":{"href":"https://api.github.com/repos/FPtje/MySQLite/issues/3"},"comments":{"href":"https://api.github.com/repos/FPtje/MySQLite/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FPtje/MySQLite/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/FPtje/MySQLite/statuses/2e1661c620d9d985d636f34282bfa213ed1d26bc"}}}}