summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2014-10-27 22:03:54 +0000
committerTed Trask <ttrask01@yahoo.com>2014-10-27 22:03:54 +0000
commitc0e97287356157dfdeaba0914863761b72fb59fb (patch)
tree485effab119451cf143665c39734b58990bf3b59
parent5ccee3fb707400c32e4fc21809cae2a32331d33a (diff)
downloadacf-lib-c0e97287356157dfdeaba0914863761b72fb59fb.tar.bz2
acf-lib-c0e97287356157dfdeaba0914863761b72fb59fb.tar.xz
Added listkeycolumns function to db library
-rw-r--r--db.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/db.lua b/db.lua
index 18af1f3..0e8848f 100644
--- a/db.lua
+++ b/db.lua
@@ -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