Skip to content
Permalink
Browse files

Added gateways functions to get informations about active f-keys

  • Loading branch information...
tvannini committed May 14, 2019
1 parent 851907e commit a21fd103fec63f58a507006b90eaf35b0d984845
Showing with 198 additions and 16 deletions.
  1. +27 −8 lib/dbms/jxdb_jxmdb.inc
  2. +55 −0 lib/dbms/jxdb_mssql.inc
  3. +49 −0 lib/dbms/jxdb_postgres.inc
  4. +23 −0 lib/dbms/jxdb_sqlite3.inc
  5. +44 −8 lib/jxcore.inc
@@ -796,8 +796,6 @@ function o2_jxmdb_recordset($server,
* $main_fields and $ref_fields are list of filed names, from main and referenced
* tables to create the key on.
*
* === NOT IMPLEMENTED YET ===
*
* @param string $server
* @param string $user
* @param string $password
@@ -845,8 +843,6 @@ function o2_jxmdb_fkeyadd($server,
/**
* Alter jxmdb table to remove a foreign key.
*
* === NOT IMPLEMENTED YET ===
*
* @param string $server
* @param string $user
* @param string $password
@@ -879,8 +875,6 @@ function o2_jxmdb_fkeyremove($server,
/**
* Validate a foreign key in jxmdb table against existing data.
*
* === NOT IMPLEMENTED YET ===
*
* @param string $server
* @param string $user
* @param string $password
@@ -913,8 +907,6 @@ function o2_jxmdb_fkeyvalidate($server,
/**
* Returns the list of existing foreign keys for jxmdb table
*
* === NOT IMPLEMENTED YET ===
*
* @param string $server
* @param string $user
* @param string $password
@@ -941,6 +933,33 @@ function o2_jxmdb_fkeystablist($server,
}
/**
* Returns the list of existing foreign keys for jxmdb db-schema and some informations
* about constraints
*
* @param string $server
* @param string $user
* @param string $password
* @param string $database
* @param string $owner
* @return array
*/
function o2_jxmdb_fkeysinfo($server,
$user,
$password,
$database,
$owner) {
return o2_jxmdb_execute('fkeysinfo'.o2_jxmdb_s.
$server.o2_jxmdb_s.
$user.o2_jxmdb_s.
$password.o2_jxmdb_s.
$database.o2_jxmdb_s.
$owner.o2_jxmdb_s);
}
/**
* Commit open transaction on sqlite database
*
@@ -1884,6 +1884,61 @@ function o2_mssql_fkeystablist($server,
}
/**
* Returns the list of existing foreign keys for MSSQL db-schema and some informations
* about constraints
*
* @param string $server
* @param string $user
* @param string $password
* @param string $database
* @param string $owner
* @return array
*/
function o2_mssql_fkeysinfo($server,
$user,
$password,
$database,
$owner) {
$query = "USE ".$database."; ".
"SELECT c.CONSTRAINT_NAME AS ".o2_mssql_o."CN".o2_mssql_c.", ".
"c.TABLE_NAME AS ".o2_mssql_o."ON".o2_mssql_c.", ".
"COL_NAME(fc.parent_object_id, fc.parent_column_id) AS ".
o2_mssql_o."SK".o2_mssql_c.", ".
"OBJECT_NAME (f.referenced_object_id) AS ".o2_mssql_o."TO".o2_mssql_c.", ".
"COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS ".
o2_mssql_o."TK".o2_mssql_c." ".
"FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c ".
"INNER JOIN sys.foreign_keys AS f ".
"ON c.CONSTRAINT_NAME = f.name ".
"INNER JOIN sys.foreign_key_columns AS fc ".
"ON f.OBJECT_ID = fc.constraint_object_id ".
"WHERE c.CONSTRAINT_CATALOG='".$database."' AND ".
"c.CONSTRAINT_SCHEMA='".$owner."'";
try {
$res = o2_mssql_execute($query, $server, $user, $password, false, false);
}
catch (o2_exception $o2e) {
$o2e->set_error_class(o2error_DBTABLEINFO);
throw $o2e;
}
$list = array();
foreach ($res as $c) {
if (!isset($list[$c["CN"]])) {
$list[$c["CN"]] = array("ON" => $c["ON"],
"TO" => $c["TO"],
"SK" => array(),
"TK" => array());
}
$list[$c["CN"]]["SK"][] = $c["SK"];
$list[$c["CN"]]["TK"][] = $c["TK"];
}
return $list;
}
/**
* Commit open transaction on mssql database
*
@@ -1706,6 +1706,55 @@ function o2_postgres_fkeystablist($server,
}
/**
* Returns the list of existing foreign keys for Postgres db-schema and some informations
* about constraints
*
* @param string $server
* @param string $user
* @param string $password
* @param string $database
* @param string $owner
* @return array
*/
function o2_postgres_fkeysinfo($server,
$user,
$password,
$database,
$owner) {
$query = "SELECT x.conname ".o2_postgres_o."CN".o2_postgres_c.",".
" x.conkey ".o2_postgres_o."SK".o2_postgres_c.",".
" x.confkey ".o2_postgres_o."TK".o2_postgres_c.",".
" pk.relname ".o2_postgres_o."ON".o2_postgres_c.",".
" fk.relname ".o2_postgres_o."TO".o2_postgres_c." ".
"FROM pg_catalog.pg_constraint x ".
"INNER JOIN pg_catalog.pg_class pk ON x.conrelid!=0 AND x.conrelid=pk.oid ".
"INNER JOIN pg_catalog.pg_class fk ON x.confrelid!=0 AND x.confrelid=fk.oid".
" INNER JOIN information_schema.table_constraints tc ON ".
"x.conname=tc.constraint_name ".
"WHERE x.contype='f' AND ".
"tc.constraint_catalog='".$database."' AND ".
"tc.constraint_schema='".$owner."'";
try {
$res = o2_postgres_execute($query, $server, $user, $password, false, false);
}
catch (o2_exception $o2e) {
$o2e->set_error_class(o2error_DBTABLEINFO);
throw $o2e;
}
$list = array();
foreach ($res as $c) {
$list[$c["CN"]] = array("ON" => $c["ON"],
"TO" => $c["TO"],
"SK" => explode(',', substr($c["SK"], 1, -1)),
"TK" => explode(',', substr($c["TK"], 1, -1)));
}
return $list;
}
/**
* Commit open transaction on Postgres database
*
@@ -1300,6 +1300,29 @@ function o2_sqlite3_fkeystablist($server,
}
/**
* Returns the list of existing foreign keys for SQLite3 db-schema and some informations
* about constraints
*
* === NOT IMPLEMENTED YET ===
*
* @param string $server
* @param string $user
* @param string $password
* @param string $database
* @param string $owner
* @return array
*/
function o2_sqlite3_fkeysinfo($server,
$user,
$password,
$database,
$owner) {
return array();
}
/**
* Commit open transaction on sqlite database
*
@@ -5003,7 +5003,7 @@ class o2_gateway {
/**
* Returns the list of existing foreign keys for database
* Returns the list of existing foreign keys for table
*
* @param string $type
* @param string $server
@@ -5022,14 +5022,50 @@ class o2_gateway {
$owner,
$table) {
$o2fkeycreate = "o2_".$type."_fkeystablist";
$o2fkeyslist = "o2_".$type."_fkeystablist";
try {
$res_val = $o2fkeycreate($server,
$user,
$password,
$database,
$owner,
$table);
$res_val = $o2fkeyslist($server,
$user,
$password,
$database,
$owner,
$table);
}
catch (o2_exception $o2e) {
$o2e->send();
$res_val = false;
$res_val = array();
}
return $res_val;
}
/**
* Returns the list of existing foreign keys for database
*
* @param string $type
* @param string $server
* @param string $user
* @param string $password
* @param string $database
* @param string $owner
* @return boolean
*/
static function fkeysinfo($type,
$server,
$user,
$password,
$database,
$owner) {
$o2fkeysinfo = "o2_".$type."_fkeysinfo";
try {
$res_val = $o2fkeysinfo($server,
$user,
$password,
$database,
$owner);
}
catch (o2_exception $o2e) {
$o2e->send();

0 comments on commit a21fd10

Please sign in to comment.
You can’t perform that action at this time.