{"id":70,"date":"2011-02-12T18:34:06","date_gmt":"2011-02-12T09:34:06","guid":{"rendered":"http:\/\/www.furelo.jp\/wordpress\/?p=70"},"modified":"2011-02-12T19:54:33","modified_gmt":"2011-02-12T10:54:33","slug":"lua%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%8b%e3%82%89mysql%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab","status":"publish","type":"post","link":"http:\/\/www.furelo.jp\/wordpress\/2011\/02\/12\/lua%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%8b%e3%82%89mysql%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab\/","title":{"rendered":"Lua\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089MySQL\u3092\u5229\u7528\u3059\u308b\u30b5\u30f3\u30d7\u30eb"},"content":{"rendered":"Lua\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089MySQL\u306bDB\u4f5c\u6210\u30fbINSERT\u30fbSELECT\u3092\u884c\u3046\u30b5\u30f3\u30d7\u30eb\u3002\r\n\r\n\u203bCentOS\u306e\u5834\u5408\u3001EPEL\u306elua\u3068lua-sql-mysql\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5165\u308c\u3066\u304a\u304f\u3053\u3068\u3002\r\n\r\n[lua]\r\nrequire &quot;luasql.mysql&quot;\r\nrequire &quot;socket&quot;\r\n\r\nfunction rows (connection, sql_statement)\r\n  local cursor = assert (connection:execute (sql_statement))\r\n  return function ()\r\n    return cursor:fetch()\r\n  end\r\nend\r\n\r\nenv = assert(luasql.mysql())\r\ncon = assert(env:connect(&quot;DB\u540d&quot;, &quot;\u30e6\u30fc\u30b6\u30fcID&quot;, &quot;\u30d1\u30b9\u30ef\u30fc\u30c9&quot;, localhost, 3306))\r\n\r\nres = con:execute([[\r\n        DROP TABLE logging\r\n]])\r\n\r\nres = assert(con:execute([[\r\n        CREATE TABLE logging (\r\n        name varchar(50),\r\n        value varchar(50)\r\n        )\r\n]]))\r\n\r\n&#8212; \u30ec\u30b3\u30fc\u30c9\u4f5c\u6210\r\nx = socket.gettime()\r\nlist = {}\r\nfor i=1,100000 do\r\n        table.insert(list, { name=&quot;Test1&quot;, value=&quot;Test1 Value&quot;, });\r\nend\r\nprint(string.format(&quot;Initialize elapsed time: %.6f\\n&quot;, socket.gettime() &#8211; x))\r\n\r\n&#8212; \u30ec\u30b3\u30fc\u30c9\u3092DB\u306bINSERT\r\nfor i,p in pairs (list) do\r\n        res = assert (con:execute(string.format([[\r\n                INSERT INTO logging\r\n                VALUES (&#8216;%s&#8217;, &#8216;%s&#8217;)]], p.name, p.value)\r\n        ))\r\nend\r\nprint(string.format(&quot;Insert elapsed time: %.6f\\n&quot;, socket.gettime() &#8211; x))\r\n\r\n\r\n&#8212; DB\u304b\u3089\u30ec\u30b3\u30fc\u30c9\u53d6\u5f97(\u30a4\u30c6\u30ec\u30fc\u30bf\u672a\u4f7f\u7528\u7248)\r\ncur = assert(con:execute([[\r\n        SELECT name, value from logging\r\n]]))\r\nprint(string.format(&quot;Execute elapsed time: %.6f\\n&quot;, socket.gettime() &#8211; x))\r\nprint(&quot;Num is &quot;.. cur:numrows());\r\nrow = cur:fetch({}, &quot;a&quot;)\r\nwhile row do\r\n&#8212;      print(string.format(&quot;Name: %s, Value: %s&quot;, row.name, row.value))\r\n        row = cur:fetch(row, &quot;a&quot;)\r\nend\r\nprint(string.format(&quot;Fetch elapsed time: %.6f\\n&quot;, socket.gettime() &#8211; x))\r\ncur:close()\r\n\r\n\r\n&#8212; DB\u304b\u3089\u30ec\u30b3\u30fc\u30c9\u53d6\u5f97(\u30a4\u30c6\u30ec\u30fc\u30bf\u4f7f\u7528\u7248)\r\nfor name, value in rows (con, [[\r\n        SELECT name, value from logging\r\n]]) do\r\n&#8212;      print(string.format(&quot;Name: %s, Value: %s&quot;, name, value))\r\nend\r\nprint(string.format(&quot;Fetch\/Execute elapsed time: %.6f\\n&quot;, socket.gettime() &#8211; x))\r\ncur:close()\r\n\r\n\r\ncon:close()\r\nenv:close()\r\n[\/lua]\r\n","protected":false},"excerpt":{"rendered":"<p>Lua\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089MySQL\u306bDB\u4f5c\u6210\u30fbINSERT\u30fbSELECT\u3092\u884c\u3046\u30b5\u30f3\u30d7\u30eb\u3002 \u203bCentOS\u306e\u5834\u5408\u3001EPEL\u306elua\u3068lua-sql-mysql\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u5165\u308c\u3066\u304a\u304f\u3053\u3068\u3002 [lua] require &#038;quot &hellip; <a href=\"http:\/\/www.furelo.jp\/wordpress\/2011\/02\/12\/lua%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88%e3%81%8b%e3%82%89mysql%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b%e3%82%b5%e3%83%b3%e3%83%97%e3%83%ab\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"_links":{"self":[{"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/posts\/70"}],"collection":[{"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":11,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":82,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/posts\/70\/revisions\/82"}],"wp:attachment":[{"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.furelo.jp\/wordpress\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}