Re: [DB] Suggestion for field types
| From: | Alan Knowles | Date: | Sat, 10 Jan 2004 11:14:36 +0000 |
| Subject: | Re: [DB] Suggestion for field types | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24955@lists.php.net to get a copy of this message | ||
This is what it would look like in the mysql driver...
static $map = false;
if (!$map) {
$map = $_DB['global_type_map'] +
array('timestamp' => 'native')
);
}
static $needsQuotes = false;
if (!$needsQuotes) {
$needsQuotes = $_DB['global_types_need_quoting'] +
array('timestamp')
);
}
.... and inside result loop..
$res[$i]['not_null']= (bool)
preg_match('/not_null/',$res[$i]['flags']);
$res[$i]['native_sequence'] = (bool)
preg_match('/auto_increment/',$res[$i]['flags']);
$res[$i]['primary_key'] = (bool)preg_match('/primary_key/',$res[$i]['flags']);
$res[$i]['unique'] = (bool)preg_match('/unique/',$res[$i]['flags']);
$res[$i]['generic_type'] = @$map[$res[$i]['type']]; $res[$i]['needs_quotes'] = @$needsQuotes[$res[$i]['type']];although this still doesnt deal with 'defaults', and perhaps 'DESCRIBE ....{tablename}..' may be more effective here.. Regards Alan Alan Knowles wrote:
I do wonder if extending the functionality of tableInfo, is a better short term approach in moving towards DB_Schema (eg. tableInfo being a basic data Provider...) Currently supplied information: table => table name name => field name type => field type len => field length flags => field flags // from DataObjects & other info perspective..-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.comrequiresQuotes => value should be quoted.. (true|false)hasNativeSequence => autoincrement or similar (true|false)nullValid => allows NULL. (true|false) default => default value? string|int ... unique => unique flag (true|false) index => indexed??? (true|type?)genericType => boolean| int|float|numeric| date|time|datetime| char|varchar| blobGiven this information - writing a DB_Validate class should be pretty simple: $errorCode | true =DB_Validate::check($db,'tablename','columnname','data');$errorsArray | true =DB_Validate::check($db,'tablename',$array);Feel free to comment on what additional information is needed.. - or more generic types. - the ones above are based off of MDB. Regards Alan Peter wrote:So how about adding two new elements to the array returned by tableInfo(): 'generictype' (or 'peartype'?) which will contain one of a basic set of types 'nativetype' which will contain the type name as used in the create table command by the specific backend and pear-haps also 'sqltype', for the closest SQL-99 column type. This will not break code that looks for 'type', and will allow the various implementations of tableInfo() to start standardising. Kind regards, Peter