From: Nicolas Boisselier Date: Tue, 6 Feb 2018 02:35:18 +0000 (+0000) Subject: bin/nb-update X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=9591d775cbdef790fda6e6a289b312b96b81090f;p=nb.git bin/nb-update --- diff --git a/bin/nb-update b/bin/nb-update index 385d2fd4..6ab5e4c1 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -107,10 +107,10 @@ for repo in $(nb_repos); do fi echo - key="repo.$name.$branch" - nb_api_post_host_info "key=${key}.path" "val=$repo" - nb_api_post_host_info "key=${key}.exit_code" "val=$ex" - #nb_api_post_host_info "key=${key}.last_commit" val=$(cd "$repo" && git log | head -1 | awk '/^commit/ { print $2; exit; }') + nb_api_post_host_info "key=${NAME}.$repo" "val=name:$name branch:$branch" +# NB 06.02.18 key="repo.$name.$branch" +# NB 06.02.18 nb_api_post_host_info "key=${key}.path" "val=$repo" +# NB 06.02.18 nb_api_post_host_info "key=${key}.exit_code" "val=$ex" done diff --git a/etc/dbq/ldap.php b/etc/dbq/ldap.php index af04172b..f4e127be 100644 --- a/etc/dbq/ldap.php +++ b/etc/dbq/ldap.php @@ -52,7 +52,12 @@ $DBQ['ldap'] = $GLOBALS['DBQ_LDAP'] + [ 'type' => 'ldap', 'tables' => [ $filter => [ - 'fields' => ['dn','objectClass'], + #'fields' => ['dn','objectClass'], + 'fields' => [ + 'dn' => (new Field(['name'=>'dn','key'=>true])), + 'objectClass' => (new Field(['name'=>'objectClass'])), + ], + 'type' => 'table', ], ], 'default_table' => $filter, diff --git a/lib/php/db/field.php b/lib/php/db/field.php index bf0080e1..72d93f1d 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -31,8 +31,10 @@ class field extends nb { foreach ($attr as $k => $v) { $this->$k = $v; } } - public static function default2str($default) { - if ($this->default == "''") $this->default = ''; + public function default2str($default=null) { +# NB 06.02.18 Bug if ($this->default == "''") $this->default = ''; + if ($default === null) $default = $this->default; + # NB 12.12.17 if (strtoupper($default) == "NULL") $default = null; #if (strtoupper($default) == "NOW()") $default = null; # NB 08.01.18 if (strtoupper($default) == "NOW()") $default = $date_microtime(); @@ -146,12 +148,14 @@ class field extends nb { } public function sql_name_cast_text() { + if (empty($this->db())) return $this->name; $name = $this->db()->sql_name($this->name); return $this->db()->cast_text($name); } public function sql_name($cast=false) { if ($cast and !$this->text()) return $this->sql_name_cast_text(); + if (empty($this->db())) return $this->name; return $this->db()->sql_name($this->name); } @@ -292,7 +296,7 @@ class field extends nb { #if ($value === null) return ''; static $sqlite = null; if ($sqlite === null) { $db = $this->db(); - $sqlite = (bool)($db->type == 'sqlite'); + $sqlite = (bool)(!empty($db->type) and $db->type == 'sqlite'); } # Anoying, sqlite does not format properly ! diff --git a/lib/php/db/table.php b/lib/php/db/table.php index fb7f2fd4..a95222d3 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -473,7 +473,7 @@ Class Table extends nb { return $ret; } - private function fields_keys(&$others=[]) { + public function fields_keys(&$others=[]) { $fields_keys = []; @@ -542,13 +542,11 @@ Class Table extends nb { if ($values === null) $values = $this->p(); if (!is_array($values)) $values = [$values]; -# NB 23.11.17 $fields = $this->fields(); -# NB 23.11.17 $keys = $this->fields_keys(); - + if (!$add) { $sql = $this->sql_edit($values,$add); - $st = $this->db()->conn->prepare($sql); $st->execute(); + } // Params $form_hidden = ''; @@ -604,7 +602,7 @@ Class Table extends nb { # NB 08.01.18 if ($add and !preg_match('/^(null|.*\(.*)?$/',strtolower($field->default))) { # NB 08.01.18 $row[$name] = $field->default; if ($add) { - $row[$name] = $field->default2str($field->default); + $row[$name] = $field->default2str(); } elseif(!isset($row[$name])) { $row[$name] = ''; @@ -999,6 +997,17 @@ Class Table extends nb { $call = $opt['row_parse_pre']; $call($row,$this,$opt); } + // + // Fields filter + // + if ($this->fields_only) { + $new_row = []; + foreach ($this->fields_only as $k) { + if (isset($row[$k])) $new_row[$k] = $row[$k]; + } + $row = $new_row; + } + // // Format // @@ -1062,7 +1071,7 @@ Class Table extends nb { # # Fields # - $fields = $this->fields(); + $opt['fields'] = $fields = $this->fields(); if ($this->fields_only) { foreach ($fields as $k=>$v) { if (!in_array($k,$this->fields_only)) unset($fields[$k]); @@ -1087,38 +1096,38 @@ Class Table extends nb { list($sql,$where,$limit,$select_count) = $this->rows_sql($opt); $nosql = $this->db()->conf_type('nosql'); - if ($nosql) { - $sql = empty($this->sql) ? $this->name : $this->sql; - $fct = $this->db()->conf_type('prepare'); - if ($fct) $st = $fct($this,$sql); - if (!$fct = $this->db()->conf_type('fetch')) { - $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; - } - #$fct = function() { return false; }; - #$fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; - - } else { - - if ($this->db()->type == 'pgsql') { - $sql_orig = $sql; - $this->db()->conn->beginTransaction(); - $sql = "DECLARE table_rows CURSOR FOR $sql"; - $cursor = $this->db()->conn->prepare($sql); - $cursor->execute(); - $sql = "FETCH 1 FROM table_rows"; + if ($nosql) { + $sql = empty($this->sql) ? $this->name : $this->sql; + $fct = $this->db()->conf_type('rows_prepare'); + if ($fct) $st = $fct($this,$sql); + if (!$fct = $this->db()->conf_type('rows_fetch')) { + $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; + } + #$fct = function() { return false; }; + #$fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; } else { - $this->db()->conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); - } + + if ($this->db()->type == 'pgsql') { + $sql_orig = $sql; + $this->db()->conn->beginTransaction(); + $sql = "DECLARE table_rows CURSOR FOR $sql"; + $cursor = $this->db()->conn->prepare($sql); + $cursor->execute(); + $sql = "FETCH 1 FROM table_rows"; - $st = $this->db()->conn->prepare($sql);#,[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); - if (empty($cursor)) { - $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; - $st->execute(); - } else { - $fct = function() use($st) { if ($st->execute()) return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; - } -} + } else { + $this->db()->conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); + } + + $st = $this->db()->conn->prepare($sql);#,[PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT]); + if (empty($cursor)) { + $fct = function() use($st) { return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; + $st->execute(); + } else { + $fct = function() use($st) { if ($st->execute()) return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; + } + } if (!empty($opt['query'])) return $st; # # Use the module out when format unknow @@ -1182,17 +1191,6 @@ Class Table extends nb { $call = $this->rows_parsers($row,$opt); - # - # Fields filter - # - if ($this->fields_only) { - $new_row = []; - foreach ($this->fields_only as $k) { - if (isset($row[$k])) $new_row[$k] = $row[$k]; - } - $row = $new_row; - } - # # Preffix # @@ -2174,7 +2172,8 @@ Class Table extends nb { // Criterias // $r .= '
'; - foreach ( $this->fields() as $k => $f) { + if (!isset($opt['fields'])) $opt['fields'] = $this->fields(); + foreach ($opt['fields'] as $k => $f) { if ($f->is_encrypt()) continue; $v = $this->p($k); diff --git a/lib/php/db/types/ldap.php b/lib/php/db/types/ldap.php index ae37ec1e..bba01a51 100644 --- a/lib/php/db/types/ldap.php +++ b/lib/php/db/types/ldap.php @@ -8,12 +8,12 @@ $DB_TYPES['ldap'] = [ 'quote' => function($v) { return $v; }, 'nosql' => true, #'prepare' => function($sql) { return $this->ldap->prepare($sql); }, - 'prepare' => function($table,$sql) { + 'rows_prepare' => function($table,$sql) { $fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only); #foreach (array_keys($table->fields) as $k) { if (!in_array($k,$fields)) unset($table->fields[$k]); } $table->db()->ldap->prepare($sql,['attrs'=>$fields]); return $table->db()->ldap; }, - 'fetch' => function($table) { + 'rows_fetch' => function($table) { #debug($table->fields_only); #debug($table->fields_only); $row = $table->db()->ldap->fetch(); diff --git a/lib/php/ldap.php b/lib/php/ldap.php index 6e687358..7b6f79bc 100644 --- a/lib/php/ldap.php +++ b/lib/php/ldap.php @@ -135,7 +135,7 @@ class Ldap { */ } - /// PDO compatible + /// DB / PDO compatible public function setAttribute($k,$v) { } public function prepare($sql,$o=[]) { @@ -173,5 +173,15 @@ class Ldap { return $this->entry($this->entry,$dn); } + public function _field($name) { + return new Field([ + 'name' => $name, + 'type' => 'text', + ]); + } + + public function _fields_keys(&$others=[]) { + return $this->fields('dn'); + } public function closeCursor() {} } diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 4e74eda4..b8984f03 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -435,13 +435,14 @@ class DbQ extends nb { public function vi($add=false) { $all = []; + $nosql = $this->db->conf_type('nosql'); + + $fields = $this->vi_extract_fields(); $keys = $this->table->fields_keys($all); if (!$keys) $keys = $all; $keys = array_keys($keys); - $fields = $this->vi_extract_fields(); - $values = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : explode($this->param_args_sep,$this->params['args']); foreach ($values as $k=>$v) { if (!in_array($k,$keys)) unset($values[$k]); @@ -473,7 +474,7 @@ class DbQ extends nb { } public function table_rw() { - return (1 + return (int)(1 and ($this->perm >= self::READ) and !empty($this->table) and !empty($this->table->type())