Re: [PROPOSAL] DB_Simple
| From: | Alexey Borzov | Date: | Sat, 01 Nov 2003 09:32:49 +0000 |
| Subject: | Re: [PROPOSAL] DB_Simple | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-23170@lists.php.net to get a copy of this message | ||
Hi!
Overall impression: not impressed.
Paul M Jones wrote:
======== Overview -------- DB_Simple attempts to fill the space between DB, MDB, and DB_DataObject by supporting automated SQL queries, providing and easy to use configuration system, and abstracting datatypes.Two problems with the package name: 1) It is *absolutely* impossible to understand what this package does by looking at its name 2) This was raised when I proposed HTTP_SimpleClient package: "Simple" in the name implies either "dumb" or the existance of "Complex" package.
See the two attached files for the DB_Simple class and an example extension class.the "example extension class" will not work, its php4-style constructor calls its php5-style constructor but passes nothing to it.
========== Data Types ---------- Similar to MDB, DB_Simple abstracts a number of datatypes, defined as constants within the class:
- DB_SIMPLE_INTNOSIGNMySQLism?unsigned long integer, typcially BIGINT UNSIGNED
=================
Column Definition
-----------------
Finally, an example of a calculated column:
$this->column['area'] = array(
'type' => DB_SIMPLE_FLOAT,
'calc' => "length * width",
'index' => DB_SIMPLE_INDEX
);
Client-side views? How sweet.
======================== Automated Table Creation ------------------------ When you call the DB_Simple constructor, you can ask it to set up the table (based on the column map) if the table does not already exist. DB_Simple will look for the table and create it as necessary (not including calculated fields). It will also create the related column indexes as well (whether "normal" fields or calculated columns).Quoting the comment buried *deep* inside createTable(): // add the field definition ... // mysql only for now, include others later If the package supports only MySQL, then it has to have MySQL in its name. Thus people who don't use The Most Popular Open Source Database (tm) will not have to bother. This unfortunately is not the case now in PEAR, for e.g. DB_NestedSet is MySQL-only, but its name is misleading.
===============
SQL Clause Maps
---------------
To support automated SELECT statements, DB_Simple requires that you
define baseline SQL clauses for certain methods (typically getList()
and getItem(), but you can add your own if you like). Here are some
example SQL clause maps:
$this->sql['getList'] = array(
DB_SIMPLE_SELECT => array('id', 'username', 'email'),
DB_SIMPLE_WHERE => "division = 'Information Technology'",
DB_SIMPLE_ORDER => "username"
);
Is this any easier than to directly write
SELECT id, username, email
FROM tablename
WHERE division = 'Information Technology'
ORDERB BY username
The manually written query has less chars in it, BTW.
=========================================== Automated INSERT and UPDATE With Validation ------------------------------------------- DB_Simple uses DB::autoExecute in its insert() and update() methods, which means all you need to do to insert or update table rows is pass an associative-array where the key is a field name and the value is the field value. In addition, becuase the DB_Simple instance has a defined column map, it knows what to expect from every field. This, it will pre-validate all INSERT and UPDATE values to make sure they match the column requirements (datatype, size, decimla places, not-null, and so on) before attempting to connect to the database.Will it also check for column constraints, foreign keys and the like? Besides, this info is *not* read from DB, but provided by the user -> inconsistencies. And my all-time favourite error message, from delete() method: return $this->raiseError("The WHERE clause in your DELETE " .
"statement has no operator (=, <, <=, >, >=, LIKE) in it; " .
"this might delete all records. Request denied.");
Will the package also try to wipe my nose?
BTW, what about
DELETE FROM tablename WHERE 1 = 1?
============ Known Issues ------------ DB_Simple should throw error codes, not just error messages. DB_Simple has only been tested with MySQL.Once again: if this was told from the very beginning, then I wouldn't bother reading further.