The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/printthread.php(287) : eval()'d code 2 errorHandler->error
/printthread.php 287 eval
/printthread.php 117 printthread_multipage



UserSpice
DB.php patch - error handling, flexible WHERE clauses, fix bug - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: DB.php patch - error handling, flexible WHERE clauses, fix bug (/showthread.php?tid=233)

Pages: 1 2


DB.php patch - error handling, flexible WHERE clauses, fix bug - faguss - 06-06-2017

Found incompatibility - passing empty array will make ERROR: w=Array ( ) appear on the screen. Fix:

Code:
if ($wcount==0) return "";

That's line 112 in my paste.


DB.php patch - error handling, flexible WHERE clauses, fix bug - faguss - 06-14-2017

I wanted to use LIKE for comparing floats so I added it to the
Code:
$valid_ops
array. Also I implemented a bunch of other operators that might be useful in the future.

Lines 102-110, 131-155, 293-299 in my paste.

Examples: https://pastebin.com/mWvUsNAh


DB.php patch - error handling, flexible WHERE clauses, fix bug - picassoo - 06-18-2017

nice faguss, can you make all the function for all ??? like UPDATE ADD DELETE and other ?


DB.php patch - error handling, flexible WHERE clauses, fix bug - faguss - 06-18-2017

I'm not sure what you mean because UserSpice already has functions
Code:
update()
,
Code:
insert()
, and
Code:
delete()
. See documentation.

It's not called ADD but INSERT and it doesn't have a WHERE clause. See SQL tutorial.

===

With this patch you can already use nested triads for
Code:
delete()
. For example:

Code:
$db->delete("Products", ["or", ["Stock","<=",0], ["Legal","=",false]]);

I've noticed that the query is still being run even if the argument was incorrect. This is also the case with the original DB.php. For example:
Code:
delete("Products",NULL)
is going to clear the table. To fix it I've added an error flag. Lines 86-91, 98, 159, 186 in my paste.

Passing empty array is now prohibited (line 195).

===

Statement UPDATE uses WHERE clause so I might as well implement triads. Lines 239-253 in my paste. Now you can do this:

Code:
$db->update("Suppliers", ["Country","=","Greece"], ["Currency"=>"GRD"]);



DB.php patch - error handling, flexible WHERE clauses, fix bug - mudmin - 08-14-2017

@faguss
Do you have the latest version of your db class? I'll shoot you an email.