Software /
code /
prosody
Comparison
util/sql.lua @ 5887:1f860279b2f8
util.sql: Support incrementing columns
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 28 Oct 2013 23:20:25 +0100 |
parent | 5886:1237f9cc3123 |
child | 5888:f3e408ae59a6 |
comparison
equal
deleted
inserted
replaced
5886:1237f9cc3123 | 5887:1f860279b2f8 |
---|---|
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 col.primary_key == true then sql = sql.." PRIMARY KEY"; end |
266 if col.auto_increment == true then | |
267 if self.params.driver == "PostgreSQL" then | |
268 sql = sql.." SERIAL"; | |
269 elseif self.params.driver == "MySQL" then | |
270 sql = sql.." AUTO_INCREMENT"; | |
271 elseif self.params.driver == "SQLite3" then | |
272 sql = sql.." AUTOINCREMENT"; | |
273 end | |
274 end | |
266 if i ~= #table.c then sql = sql..", "; end | 275 if i ~= #table.c then sql = sql..", "; end |
267 end | 276 end |
268 sql = sql.. ");" | 277 sql = sql.. ");" |
269 if self.params.driver == "PostgreSQL" then | 278 if self.params.driver == "PostgreSQL" then |
270 sql = sql:gsub("`", "\""); | 279 sql = sql:gsub("`", "\""); |