![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Pear Pear programming, this is a very complex subject as with using pear with php can be a difficult task for some, so lets talk pear. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| quipo Wed May 16 20:31:55 2007 UTC Modified files: /pear/MDB2/MDB2/Driver/Reverse oci8.php /pear/MDB2 package_oci8.php Log: initial support for FOREIGN KEY and CHECK constraints in the Reverse module http://cvs.php.net/viewvc.cgi/pear/M...&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/oci8.php diff -u pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.62 pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.63 --- pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.62 Thu Mar 29 18:18:06 2007 +++ pear/MDB2/MDB2/Driver/Reverse/oci8.php Wed May 16 20:31:55 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.62 2007/03/29 18:18:06 quipo Exp $ +// $Id: oci8.php,v 1.63 2007/05/16 20:31:55 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -270,16 +270,35 @@ if (PEAR::isError($db)) { return $db; } - - $query = 'SELECT alc.constraint_name, - alc.constraint_type, + //querying USER_CONSTRAINTS and USER_CONS_COLUMNS is slightly faster than ALL_CONSTRAINTS and ALL_CONS_COLUMNS + $query = 'SELECT alc.constraint_name, + CASE alc.constraint_type WHEN \'P\' THEN 1 ELSE 0 END "primary", + CASE alc.constraint_type WHEN \'R\' THEN 1 ELSE 0 END "foreign", + CASE alc.constraint_type WHEN \'U\' THEN 1 ELSE 0 END "unique", + CASE alc.constraint_type WHEN \'C\' THEN 1 ELSE 0 END "check", + alc.DELETE_RULE "on_delete", + \'NO ACTION\' "on_update", + CASE alc.deferrable WHEN \'NOT DEFERRABLE\' THEN 0 ELSE 1 END "is_deferrable", + CASE alc.deferred WHEN \'IMMEDIATE\' THEN 1 ELSE 0 END "is_deferred", alc.search_condition, - alc.r_constraint_name, alc.search_condition, + alc.table_name, cols.column_name, - cols.position - FROM all_constraints alc, - all_cons_columns cols + cols.position, + r_alc.table_name "references_table", + r_cols.column_name "references_field", + r_cols.position "references_field_position" + FROM user_cons_columns cols + LEFT JOIN user_constraints alc + ON alc.constraint_name = cols.constraint_name + AND alc.owner = cols.owner + LEFT JOIN user_constraints r_alc + ON alc.r_constraint_name = r_alc.constraint_name + AND alc.r_owner = r_alc.owner + LEFT JOIN user_cons_columns r_cols + ON r_alc.constraint_name = r_cols.constraint_name + AND r_alc.owner = r_cols.owner + AND cols.position = r_cols.position WHERE (alc.constraint_name=%s OR alc.constraint_name=%s) AND alc.constraint_name = cols.constraint_name AND alc.owner = '.$db->quote(strtoupper($db->dsn['username']), 'text'); @@ -321,6 +340,20 @@ $definition['fields'][$column_name] = array( 'position' => (int)$row['position'] ); + if ($row['foreign']) { + $ref_column_name = $row['references_field']; + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + if ($db->options['field_case'] == CASE_LOWER) { + $ref_column_name = strtolower($ref_column_name); + } else { + $ref_column_name = strtoupper($ref_column_name); + } + } + $definition['references_table'] = $row['references_table']; + $definition['references_fields'][$ref_column_name] = array( + 'position' => (int)$row['references_field_position'] + ); + } $lastrow = $row; // otherwise $row is no longer usable on exit from loop } @@ -329,14 +362,16 @@ return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, $constraint_name . ' is not an existing table constraint', __FUNCTION__); } - if ($lastrow['constraint_type'] === 'P') { - $definition['primary'] = true; - } elseif ($lastrow['constraint_type'] === 'U') { - $definition['unique'] = true; - } elseif ($lastrow['constraint_type'] === 'R') { - $definition['foreign'] = $lastrow['r_constraint_name']; - } elseif ($lastrow['constraint_type'] === 'C') { - $definition['check'] = true; + $definition['primary'] = (boolean)$lastrow['primary']; + $definition['unique'] = (boolean)$lastrow['unique']; + $definition['foreign'] = (boolean)$lastrow['foreign']; + $definition['check'] = (boolean)$lastrow['check']; + $definition['is_deferrable'] = (boolean)$lastrow['is_deferrable']; + $definition['is_deferred'] = (boolean)$lastrow['is_deferred']; + $definition['on_delete'] = $lastrow['on_delete']; + $definition['on_update'] = $lastrow['on_update']; + + if ($definition['check']) { // pattern match constraint for check constraint values into enum-style output: $enumregex = '/'.$lastrow['column_name'].' in \((.+?)\)/i'; if (preg_match($enumregex, $lastrow['search_condition'], $rangestr)) { @@ -350,6 +385,9 @@ } } } + + + //echo '<hr><pre>'; print_r($definition); echo '</pre><hr>'; return $definition; } http://cvs.php.net/viewvc.cgi/pear/M...&diff_format=u Index: pear/MDB2/package_oci8.php diff -u pear/MDB2/package_oci8.php:1.119 pear/MDB2/package_oci8.php:1.120 --- pear/MDB2/package_oci8.php:1.119 Thu May 3 18:54:16 2007 +++ pear/MDB2/package_oci8.php Wed May 16 20:31:55 2007 @@ -6,6 +6,7 @@ $version = 'XXX'; $state = 'stable'; $notes = <<<EOT +- initial support for FOREIGN KEY and CHECK constraints in the Reverse module note: - please use the latest ext/oci8 version from pecl.php.net/oci8 | |||
| Featured Websites | ||||
|
![]() |
| Tags: cvs, mdb2, oci8php, package_oci8php, pear |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MDB2 - how to catch "MDB2 Error: constraint violation" error? | l Burnerheimerton | Pear | 3 | 10-12-2008 10:44 AM |
| cvs: pear /MDB2 package_mssql.php /MDB2/MDB2/Driver/Reverse mssql.php | Lorenzo Alberton | Pear | 0 | 05-20-2007 7:42 PM |
| cvs: pear /MDB2_Schema/MDB2 Schema.php /MDB2_Schema/MDB2/Schema Parser.php /MDB2_Schema/docs xml_schema_documentation.html | Igor Feghali | Pear | 0 | 05-20-2007 7:41 PM |
| cvs: pear /MDB2/MDB2/Driver mysql.php mysqli.php pgsql.php | David Coallier | Pear | 0 | 05-20-2007 7:41 PM |
| MDB2 ibase Reverse: strange case problem | Alessandro Pasotti | Pear | 3 | 05-20-2007 6:34 PM |
| Featured Websites | ||||
|