Compare commits

...

3 Commits

Author SHA1 Message Date
Clemens Schwaighofer
04b0476b4d Info TODO text 2022-03-22 20:23:44 +09:00
Clemens Schwaighofer
13fb22385b Fix DB\IO return for unset pk name to be always string
Add Test for SELECT typ query and num rows type with dbReturn
2022-03-22 20:17:30 +09:00
Clemens Schwaighofer
b7f594e683 Fix, config master base style/js, fix DB\IO num rows
DB\IO dbReturn also sets internal num_rows, num_fields, field_names so
the normal dbGet* calls can be used after dbReturn call

JAVASCRIPT/STYLESHEET in config.master is now override able from .env
file. Others will follow
2022-03-22 20:11:13 +09:00
6 changed files with 32 additions and 7 deletions

View File

@@ -3384,6 +3384,24 @@ final class CoreLibsDBIOTest extends TestCase
);
}
// if this is a select query, db dbReturn, dbReturnRow, dbReturnArray too
if (preg_match("/^(select|show|with) /i", $query)) {
// TODO also tst dbReturnRow and dbReturnArray
$res = $db->dbReturn($query);
$this->assertEquals(
$expected_rows,
$db->dbGetNumRows()
);
$this->assertEquals(
$expected_cols,
$db->dbGetNumFields()
);
$this->assertEquals(
$expected_col_names,
$db->dbGetFieldNames()
);
}
// reset all data
$db->dbExec("TRUNCATE table_with_primary_key");
$db->dbExec("TRUNCATE table_without_primary_key");

View File

@@ -69,6 +69,9 @@ $db->dbSetEncoding('SJIS');
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
$db->dbResetEncoding();
$res = $db->dbReturn("SELECT * FROM max_test");
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) {
print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
}
@@ -277,7 +280,7 @@ print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got p
// return Array Test
$query = "SELECT type, sdate, integer FROM foobar";
$data = $db->dbReturnArray($query, true);
print "Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
print "Rows: " . $db->dbGetNumRows() . ", Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
// trigger a warning
print "<b>WARNING NEXT</b><br>";

View File

@@ -1,6 +1,7 @@
{
"name": "gullevek/corelibs",
"description": "CoreLibs",
"name": "gullevek/corelibs-dev",
"version": "dev-master",
"description": "CoreLibs: Development package",
"type": "library",
"authors": [
{

View File

@@ -274,8 +274,8 @@ define('G_TITLE', $_ENV['G_TITLE'] ?? '');
/************ STYLE SHEETS / JS **********/
define('ADMIN_STYLESHEET', 'edit.css');
define('ADMIN_JAVASCRIPT', 'edit.js');
define('STYLESHEET', 'frontend.css');
define('JAVASCRIPT', 'frontend.js');
define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
// anything optional
/************* INTERNAL ******************/

View File

@@ -4,7 +4,6 @@
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/

View File

@@ -1786,9 +1786,12 @@ class IO
// count the rows returned (if select)
$this->cursor_ext[$query_hash]['num_rows'] =
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
// also set last return
$this->num_rows = $this->cursor_ext[$query_hash]['num_rows'];
// count the fields
$this->cursor_ext[$query_hash]['num_fields'] =
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
$this->num_fields = $this->cursor_ext[$query_hash]['num_fields'];
// set field names
$this->cursor_ext[$query_hash]['field_names'] = [];
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
@@ -1798,6 +1801,7 @@ class IO
$i
);
}
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
// reset first call vars
$this->cursor_ext[$query_hash]['firstcall'] = 0;
// reset the internal pos counter
@@ -2870,7 +2874,7 @@ class IO
*/
public function dbGetInsertPKName(): string
{
return $this->insert_id_pk_name;
return (string)$this->insert_id_pk_name;
}
/**