Skip to content
Permalink
Browse files

Not unique indexes runtime management stuff: functions, Connectivity,…

… ...
  • Loading branch information...
tvannini committed Sep 1, 2019
1 parent f83d22a commit 137c79b34449494ec5e9d9a050f2a36a136942d3
Showing with 258 additions and 71 deletions.
  1. +0 −1 jxconv.php
  2. +1 −1 jxrnt.php
  3. +31 −6 lib/dbms/jxdb_mssql.inc
  4. +31 −5 lib/dbms/jxdb_postgres.inc
  5. +55 −13 lib/dbms/jxdb_sqlite3.inc
  6. +110 −25 lib/jxcore.inc
  7. +2 −2 lib/jxfnx.inc
  8. +27 −17 lib/prgs/jxconnectivity.prf
  9. +1 −1 lib/prgs/jxconnectivity.prg
@@ -300,7 +300,6 @@ function add_tab_field($code, $table, $field, $name, $model) {
$res = preg_match_all('/o2def::tab\("'.$table.
'",[^;]*\);\s+(o2def::field\([^;]+\);\s+)++o2def::index/',
$code, $parts, PREG_OFFSET_CAPTURE);
// _____________________________________ Check for field already existing in table ___
if (preg_match('/o2def::field\(\s*[\'"]'.$field.'[\'"]\s*,/', $parts[0][0][0]) ===0) {
// ________________________________________________ Last field definition code ___
@@ -44,7 +44,7 @@
*
* @global string $jxbuilt
*/
$jxbuilt = "20190809";
$jxbuilt = "20190902";
/**
* Start execution time
@@ -491,7 +491,9 @@ function o2_mssql_tableindexes($server, $user, $password, $database, $owner, $ta
foreach ($res_local as $single_key) {
if (strtoupper($single_key['INDEX_NAME']) != "JXPK_".strtoupper($table)) {
$seq_no = 0;
$ret_val[$single_key['INDEX_NAME']] = array();
$unique = stripos($single_key['INDEX_DESCRIPTION'], 'unique') !== false;
$ret_val[$single_key['INDEX_NAME']] = array('unique' => $unique,
'segments' => array());
foreach (explode(",", $single_key['INDEX_KEYS']) as $single_segment) {
if (strpos($single_segment, "(-)")) {
$single_segment = trim(str_replace("(-)", "", $single_segment));
@@ -501,7 +503,7 @@ function o2_mssql_tableindexes($server, $user, $password, $database, $owner, $ta
$single_segment = trim($single_segment);
$dir_local = "A";
}
$ret_val[$single_key['INDEX_NAME']]+=
$ret_val[$single_key['INDEX_NAME']]['segments']+=
array($seq_no => array('column' => $single_segment,
'dir' => $dir_local));
$seq_no++;
@@ -691,6 +693,19 @@ function o2_mssql_renametable($server,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "indexes" => array([idx_1] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [idx_2] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [...]
* [idx_n] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "primary" => array([pkeyname] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
@@ -716,8 +731,8 @@ function o2_mssql_createtable($server,
$execute = true) {
$query = "CREATE TABLE ".o2_mssql_o.$database.o2_mssql_c.".".
o2_mssql_o.$owner.o2_mssql_c.".".
o2_mssql_o.$table.o2_mssql_c." (\n";
o2_mssql_o.$owner.o2_mssql_c.".".
o2_mssql_o.$table.o2_mssql_c." (\n";
$type = "";
$default = "";
foreach ($structure["fields"] as $field_name => $field_prop) {
@@ -738,13 +753,23 @@ function o2_mssql_createtable($server,
}
$query.= "ADD CONSTRAINT JXPK_".$table." PRIMARY KEY CLUSTERED (".
o2_mssql_indexfields_create($pk_segments).") ON [PRIMARY]\n";
// _______________________________________________________________________ INDEXES ___
// ________________________________________________________________ UNIQUE INDEXES ___
foreach ($structure["keys"] as $index_name => $index_segs) {
$query.= o2_mssql_index_create($index_name,
$index_segs,
$table,
$database,
$owner)."\n";
$owner,
true)."\n";
}
// ____________________________________________________________ NOT UNIQUE INDEXES ___
foreach ($structure["indexes"] as $index_name => $index_segs) {
$query.= o2_mssql_index_create($index_name,
$index_segs,
$table,
$database,
$owner,
false)."\n";
}
if ($execute) {
try {
@@ -417,9 +417,10 @@ function o2_postgres_tableindexes($server, $user, $password, $database, $owner,
if ($single_key['INDEXNAME'] != $table."_pkey") {
$index = substr($single_key['INDEXNAME'], strlen($table) + 1);
$segments = array();
$unique = stripos($single_key['INDEXDEF'], 'CREATE UNIQUE INDEX') !== false;
preg_match('/\(([^(]*)\)/', $single_key['INDEXDEF'], $segments);
$segments = explode(",", $segments[1]);
$ret_val[$index] = array();
$ret_val[$index] = array('unique' => $unique, 'segments' => array());
$seq = 0;
foreach ($segments as $seg) {
list($seg, $dir) = explode(" ", trim($seg));
@@ -430,8 +431,10 @@ function o2_postgres_tableindexes($server, $user, $password, $database, $owner,
$desc = false;
}
$seg = rtrim(ltrim($seg, o2_postgres_o), o2_postgres_c);
$ret_val[$index]+= array($seq => array('column' => $seg,
'dir' => ($desc ? "D" : "A")));
$ret_val[$index]['segments']+= array($seq =>
array('column' => $seg,
'dir' => ($desc ?
"D" : "A")));
$seq++;
}
}
@@ -625,6 +628,19 @@ function o2_postgres_renametable($server,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "indexes" => array([idx_1] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [idx_2] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [...]
* [idx_n] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "primary" => array([pkeyname] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
@@ -672,13 +688,23 @@ function o2_postgres_createtable($server,
o2_postgres_o.$table.o2_postgres_c.
" ADD PRIMARY KEY (".
o2_postgres_indexfields_create($pk_segments, false).")";
// _______________________________________________________________________ INDEXES ___
// ________________________________________________________________ UNIQUE INDEXES ___
foreach ($structure["keys"] as $key_name => $key_segs) {
$script[$key_name] = o2_postgres_index_create($key_name,
$key_segs,
$table,
$database,
$owner);
$owner,
true);
}
// ____________________________________________________________ NOT UNIQUE INDEXES ___
foreach ($structure["indexes"] as $idx_name => $idx_segs) {
$script[$idx_name] = o2_postgres_index_create($idx_name,
$idx_segs,
$table,
$database,
$owner,
false);
}
if ($execute) {
try {
@@ -402,27 +402,45 @@ function o2_sqlite3_tableindexes($server, $user, $password, $database, $owner, $
if ($key_name != $database.$table."_PK" &&
!strpos(strtoupper($key_name), "AUTOINDEX")) {
if (!isset($ret_val[$key_name])) {
$ret_val[str_replace($database.$table."_", "", $key_name)] = array();
$ret_val[str_replace($database.$table."_", "", $key_name)] =
array('unique' => $single_key['unique'], 'segments' => array());
}
$query_local = "PRAGMA index_info(".o2_sqlite3_o.$key_name.o2_sqlite3_c.")";
$query_info = "SELECT ".o2_sqlite3_o."sql".o2_sqlite3_c." ".
o2_sqlite3_o."SQL".o2_sqlite3_c.
" FROM ".o2_sqlite3_o."sqlite_master".o2_sqlite3_c.
" WHERE ".o2_sqlite3_o."type".o2_sqlite3_c."='index' and ".
o2_sqlite3_o."tbl_name".o2_sqlite3_o."='".$table."' and ".
o2_sqlite3_o."name".o2_sqlite3_c."='".$key_name."'";
try {
$res_key = o2_sqlite3_execute($query_local,
$server,
$user,
$password,
false,
false);
$res_key = o2_sqlite3_execute($query_local,
$server,
$user,
$password,
false,
false);
$key_info = o2_sqlite3_execute($query_info,
$server,
$user,
$password,
false,
false);
}
catch (o2_exception $o2e) {
$res_key = array();
$o2e->set_error_class(o2error_DBTABLEINFO);
throw $o2e;
}
foreach ($res_key as $single_segment) {
$ret_val[str_replace($database.$table."_", "", $key_name)]+=
$parts = array();
preg_match('/'.o2_sqlite3_o.$single_segment['name'].o2_sqlite3_c.
' (ASC|DESC)/',
$key_info[0]['SQL'],
$parts);
$ret_val[str_replace($database.$table."_", "", $key_name)]['segments']+=
array($single_segment['seqno'] =>
array('column' => $single_segment['name'],
'dir' => ""));
'dir' => $parts[1] == 'ASC' ? 'A' : 'D'));
}
}
}
@@ -544,7 +562,6 @@ function o2_sqlite3_renametable($server,
$owner,
$table,
$new_name) {
try {
// _____________________________________________________ Copy existing indexes ___
$keys_query = array();
@@ -554,13 +571,14 @@ function o2_sqlite3_renametable($server,
$database,
$owner,
$table);
foreach ($keys as $keyname => $key) {
$arr_local = array();
foreach ($key as $keystructure) {
foreach ($key['segments'] as $keystructure) {
$arr_local[] = o2_sqlite3_o.$keystructure['column'].o2_sqlite3_c.
($keystructure['dir'] == "D" ? " DESC" : " ASC");
}
$keys_query[]= "CREATE UNIQUE INDEX ".
$keys_query[]= "CREATE".($key['unique'] ? " UNIQUE" : "")." INDEX ".
o2_sqlite3_o.$database.$new_name."_".$keyname.o2_sqlite3_c.
" ON ".o2_sqlite3_o.$database.$new_name.o2_sqlite3_c." (".
implode(",", $arr_local).")\n";
@@ -635,6 +653,19 @@ function o2_sqlite3_renametable($server,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "indexes" => array([idx_1] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [idx_2] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D),
* [...]
* [idx_n] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
* [field_n] => A|D)),
* "primary" => array([pkeyname] => array([field_1] => A|D,
* [field_2] => A|D,
* [...]
@@ -714,8 +745,8 @@ function o2_sqlite3_createtable($server,
}
$query_local.= "CONSTRAINT ".$database.$table."_PK PRIMARY KEY (".
implode(",", $arr_local)."))\n";
// _______________________________________________________________________ Indexes ___
$indexes_queries = array();
// ________________________________________________________________ Unique indexes ___
foreach ($structure["keys"] as $index_name => $index_segs) {
$arr_local = array();
foreach ($index_segs as $field_name => $direction) {
@@ -726,6 +757,17 @@ function o2_sqlite3_createtable($server,
" ON ".o2_sqlite3_o.$database.$table.o2_sqlite3_c." (".
implode(",", $arr_local).")\n";
}
// ____________________________________________________________ Not unique indexes ___
foreach ($structure["indexes"] as $index_name => $index_segs) {
$arr_local = array();
foreach ($index_segs as $field_name => $direction) {
$arr_local[] = $field_name.($direction == "D" ? " DESC" : " ASC");
}
$indexes_queries[]= "CREATE INDEX ".
o2_sqlite3_o.$database.$table."_".$index_name.o2_sqlite3_c.
" ON ".o2_sqlite3_o.$database.$table.o2_sqlite3_c." (".
implode(",", $arr_local).")\n";
}
if ($execute) {
try {
o2_sqlite3_execute($query_local, $server, $user, $password, true, true);

0 comments on commit 137c79b

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