Comparison

util/sql.lua @ 5886:1237f9cc3123

util.sql: Allow columns to be marked the primary key
author Kim Alvefur <zash@zash.se>
date Mon, 28 Oct 2013 23:19:47 +0100
parent 5885:cbc25ae1eea0
child 5887:1f860279b2f8
comparison
equal deleted inserted replaced
5885:cbc25ae1eea0 5886:1237f9cc3123
260 function engine:_create_table(table) 260 function engine:_create_table(table)
261 local sql = "CREATE TABLE `"..table.name.."` ("; 261 local sql = "CREATE TABLE `"..table.name.."` (";
262 for i,col in ipairs(table.c) do 262 for i,col in ipairs(table.c) do
263 sql = sql.."`"..col.name.."` "..col.type; 263 sql = sql.."`"..col.name.."` "..col.type;
264 if col.nullable == false then sql = sql.." NOT NULL"; end 264 if col.nullable == false then sql = sql.." NOT NULL"; end
265 if col.primary_key == true then sql = sql.." PRIMARY KEY"; end
265 if i ~= #table.c then sql = sql..", "; end 266 if i ~= #table.c then sql = sql..", "; end
266 end 267 end
267 sql = sql.. ");" 268 sql = sql.. ");"
268 if self.params.driver == "PostgreSQL" then 269 if self.params.driver == "PostgreSQL" then
269 sql = sql:gsub("`", "\""); 270 sql = sql:gsub("`", "\"");