diff options
author | Ted Trask <ttrask01@yahoo.com> | 2014-10-27 22:03:54 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2014-10-27 22:03:54 +0000 |
commit | c0e97287356157dfdeaba0914863761b72fb59fb (patch) | |
tree | 485effab119451cf143665c39734b58990bf3b59 | |
parent | 5ccee3fb707400c32e4fc21809cae2a32331d33a (diff) | |
download | acf-lib-c0e97287356157dfdeaba0914863761b72fb59fb.tar.bz2 acf-lib-c0e97287356157dfdeaba0914863761b72fb59fb.tar.xz |
Added listkeycolumns function to db library
-rw-r--r-- | db.lua | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -148,6 +148,21 @@ export.listcolumns = function(dbobject, table) return result end +export.listkeycolumns = function(dbobject, table) + local result = {} + if dbobject.engine == mymodule.engine.postgresql then + local col = dbobject.getselectresponse("SELECT pg_attribute.attname AS field FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = '"..dbobject.escape(table).."'::regclass AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary") + if nil == next(col) then + result = export.listcolumns(dbobject, table) + else + for i,c in ipairs(col) do + result[#result+1] = c.field + end + end + end + return result +end + export.listdatabases = function(dbobject) local result = {} if dbobject.engine == mymodule.engine.postgresql then |