webmcp
changeset 51:791849c58105
class_prototype.object:try_save() can create rows with DEFAULT VALUES
author | jbe |
---|---|
date | Fri Jun 10 14:23:35 2011 +0200 (2011-06-10) |
parents | 8026a0330598 |
children | 2a3257f29c02 |
files | libraries/mondelefant/mondelefant.lua |
line diff
1.1 --- a/libraries/mondelefant/mondelefant.lua Mon Nov 08 01:55:31 2010 +0100 1.2 +++ b/libraries/mondelefant/mondelefant.lua Fri Jun 10 14:23:35 2011 +0200 1.3 @@ -1116,16 +1116,28 @@ 1.4 end 1.5 self.id = db_result2.id 1.6 else 1.7 - local db_error, db_result = self._connection:try_query( 1.8 - { 1.9 - 'INSERT INTO $ ($) VALUES ($) RETURNING ($)', 1.10 - {self._class:get_qualified_table()}, 1.11 - fields, 1.12 - values, 1.13 - primary_key_sql 1.14 - }, 1.15 - "object" 1.16 - ) 1.17 + local db_error, db_result 1.18 + if #fields == 0 then 1.19 + db_error, db_result = self._connection:try_query( 1.20 + { 1.21 + 'INSERT INTO $ DEFAULT VALUES RETURNING ($)', 1.22 + {self._class:get_qualified_table()}, 1.23 + primary_key_sql 1.24 + }, 1.25 + "object" 1.26 + ) 1.27 + else 1.28 + db_error, db_result = self._connection:try_query( 1.29 + { 1.30 + 'INSERT INTO $ ($) VALUES ($) RETURNING ($)', 1.31 + {self._class:get_qualified_table()}, 1.32 + fields, 1.33 + values, 1.34 + primary_key_sql 1.35 + }, 1.36 + "object" 1.37 + ) 1.38 + end 1.39 if db_error then 1.40 return db_error 1.41 end