Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter

propel
Discussion topic

Back to topic list

Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter

Reply

Author =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com>
Full name =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com>
Date 2007-01-14 22:03:31 PST
Message Hi guys,

this changeset (http://propel.phpdb.​org/trac/changeset/5​41)
implements the following features:

- <attributes> in runtime-conf.xml to complement <options> (some PDO
settings must be done via driver options, i.e. while constructing,
others via attributes, i.e. using setAttribute() on the connection
instance)
- support for PDO::CONSTANT as IDs in <attribute> and <option>
(CONSTANT without PDO:: prefix still works)
- support for PDO::CONSTANT as values in <attribute> and <option>
- initConnection() method on DBAdapter to do initialization of
connections, controlled via <settings> in runtime-conf.xml (more below)
- <settings> block in runtime-conf.php to control the above
initialization
- <setting id="queries"> (expects arbitrary child tags) to run SQL
queries for connection initialization
- <setting id="charset">utf8​</setting> for DBMySQL and DBMySQLi
(isn't that one obsolete now?) to set connection character encoding

I only added the "queries" setting because I thought someone might
find it useful. If anyone objects, we can easily throw it out again.

See http://propel.phpdb.​org/trac/browser/bra​nches/1.3/generator/​
projects/bookstore/r​untime-conf.xml?rev=​541 for an example of the new
features.

Also, if someone isn't comfortable with any of the names (like
"<settings>" in the runtime config) or the way the initialization is
done via DBAdapter::initConnection() etc. please speak up :)

Cheers,

David


Am 15.01.2007 um 06:52 schrieb propel at svn dot phpdb dot org:

> Author: david
> Date: 2007-01-15 05:52:22 +0000 (Mon, 15 Jan 2007)
> New Revision: 541
>
> Modified:
> branches/1.3/generat​or/projects/bookstor​e/runtime-conf.xml
> branches/1.3/runtime​/classes/propel/Prop​el.php
> branches/1.3/runtime​/classes/propel/adap​ter/DBAdapter.php
> branches/1.3/runtime​/classes/propel/adap​ter/DBMySQL.php
> Log:
> added support for PDO attributes (set after connection is created).
> work similar to <options> in config, just with <attributes> and
> <attribute> tag name. also added support for PDO::CONSTANT as
> values (also works for names). added support for connection
> settings used to initialize the conneciton after construction, this
> is done by the respective adapter. all adapters support the queries
> setting that allows to run arbitrary SQL queries after
> initialization. added support for MySQL connection character
> encoding, done via charset setting, e.g. <setting
> name=charset>utf8​</setting>. look at bookstore runtime-conf.php for
> examples.
>
> Modified: branches/1.3/generat​or/projects/bookstor​e/runtime-conf.xml
> ====================​====================​====================​=======
> --- branches/1.3/generat​or/projects/bookstor​e/runtime-conf.xml
> 2007-01-11 21:48:44 UTC (rev 540)
> +++ branches/1.3/generat​or/projects/bookstor​e/runtime-conf.xml
> 2007-01-15 05:52:22 UTC (rev 541)
> @@ -52,11 +52,26 @@
> -->
> <options>
> <option id="ATTR_PERSISTENT"​>false</option​>
> - <!-- for MySQL, you should also turn on prepared statement
> emulation, as
> - prepared statements support is buggy in mysql driver
> + </options>
> +
> + <attributes>
> + <!-- for MySQL, you should also turn on prepared statement
> emulation, as prepared statements support is buggy in mysql driver
> <option id="ATTR_EMULATE_PRE​PARES">true</o​ption>
> -->
> - </options>
> + </attributes>
> +
> + <settings>
> + <!-- for MySQL 5, you'll likely need this
> + <setting name="charset">ut​f8</setting>
> + -->
> +
> + <!-- you can also execute arbitrary queries after the
> connection is created
> + <setting name="queries">
> + <query>SELECT * FROM foo</query>
> + <query>INSERT INTO BAR ('hey', 'there')</query>
> + </setting>
> + -->
> + </settings>
> </connection>
> </datasource>
>
>
> Modified: branches/1.3/runtime​/classes/propel/Prop​el.php
> ====================​====================​====================​=======
> --- branches/1.3/runtime​/classes/propel/Prop​el.php 2007-01-11
> 21:48:44 UTC (rev 540)
> +++ branches/1.3/runtime​/classes/propel/Prop​el.php 2007-01-15
> 05:52:22 UTC (rev 541)
> @@ -431,7 +431,8 @@
> $user = isset($conparams['user']) ? $conparams['user'] : null;
> $password = isset($conparams['password']) ? $conparams
> ['password'] : null;
>
> - // load any driver options from the INI file
> + // load any driver options from the config file
> + // driver options are those PDO settings that have to be passed
> during the connection construction
> $driver_options = array();
> if ( isset($conparams['options']) && is_array($conparams
> ['options']) ) {
> try {
> @@ -448,13 +449,31 @@
> } catch (PDOException $e) {
> throw new PropelException("Unable to open PDO connection", $e);
> }
> +
> + // load any connection options from the config file
> + // connection attributes are those PDO flags that have to be
> set on the initialized connection
> + if(isset($conparams​['attributes']) && is_array($conparams
> ['attributes'])) {
> + $attributes = array();
> + try {
> + self::processDriverOptions( $conparams['attributes'],
> $attributes );
> + } catch (PropelException $e) {
> + throw new PropelException('Error processing connection
> attributes for datasource ['.$name.']', $e);
> + }
> + foreach($attributes as $key => $value) {
> + $con->setAttribute($key, $value);
> + }
> + }
> +
> + // initialize the connection using the settings provided in the
> config file. this could be a "SET NAMES <charset>" query for MySQL,
> for instance
> + $adapter = self::getDB($name);
> + $adapter->initCo​nnection($con, isset($conparams['settings']) &&
> is_array($conparams​['settings']) ? $conparams['settings'] : array());
> }
>
> return self::$connectionMap[$name];
> }
>
> /**
> - * Internal function to handle driver_options in PDO
> + * Internal function to handle driver options or conneciton
> attributes in PDO.
> *
> * Process the INI file flags to be passed to each connection.
> *
> @@ -465,15 +484,26 @@
> */
> private static function processDriverOptions($source, &$write_to)
> {
> - foreach ($source as $option => $optiondata) {
> - $constant = 'PDO::'.$option;
> - $option_value = $optiondata['value'];
> - if ( defined ($constant) ) {
> - $constant_value = constant($constant);
> - $write_to[$constant_value] = $option_value;
> - } else {
> - throw new PropelException("Invalid PDO option specified: ".
> $option." = ".$option_value);
> + foreach($source as $option => $optiondata) {
> + if(is_string($option) && strpos($option, 'PDO::') !== false) {
> + $key = $option;
> + } elseif(is_string($option)) {
> + $key = 'PDO::' . $option;
> }
> + if(!defined($key)) {
> + throw new PropelException("Invalid PDO option/attribute name
> specified: ".$key);
> + }
> + $key = constant($key);
> +
> + $value = $optiondata['value'];
> + if(is_string($value) && strpos($value, 'PDO::')) {
> + if(!defined($value)) {
> + throw new PropelException("Invalid PDO option/attribute value
> specified: ".$value);
> + }
> + $value = constant($value);
> + }
> +
> + $write_to[$key] = $value;
> }
> }
>
>
> Modified: branches/1.3/runtime​/classes/propel/adap​ter/DBAdapter.php
> ====================​====================​====================​=======
> --- branches/1.3/runtime​/classes/propel/adap​ter/DBAdapter.php
> 2007-01-11 21:48:44 UTC (rev 540)
> +++ branches/1.3/runtime​/classes/propel/adap​ter/DBAdapter.php
> 2007-01-15 05:52:22 UTC (rev 541)
> @@ -81,11 +81,31 @@
> throw new PropelException("Unsupported Propel driver: " .
> $driver . ": Check your configuration file");
> }
> }
> +
> + /**
> + * This method is called after a connection was created to run
> necessary
> + * post-initialization queries or code.
> + *
> + * This base method runs queries specified using the "query"
> setting.
> + *
> + * @param PDO A PDO connection instance.
> + * @param array An array of settings.
> + */
> + public function initConnection(PDO $con, array $settings)
> + {
> + if(isset($settings['queries']) && is_array($settings['queries'])) {
> + foreach($settings['queries'] as $queries) {
> + foreach((array)$queries as $query) {
> + $con->query($query);
> + }
> + }
> + }
> + }
>
> /**
> * This method is used to ignore case.
> *
> - * @param in The string to transform to upper case.
> + * @param string The string to transform to upper case.
> * @return string The upper case string.
> */
> public abstract function toUpperCase($in);
>
> Modified: branches/1.3/runtime​/classes/propel/adap​ter/DBMySQL.php
> ====================​====================​====================​=======
> --- branches/1.3/runtime​/classes/propel/adap​ter/DBMySQL.php
> 2007-01-11 21:48:44 UTC (rev 540)
> +++ branches/1.3/runtime​/classes/propel/adap​ter/DBMySQL.php
> 2007-01-15 05:52:22 UTC (rev 541)
> @@ -33,6 +33,21 @@
> class DBMySQL extends DBAdapter {
>
> /**
> + * This method is called after a connection was created to run
> necessary
> + * post-initialization queries or code.
> + *
> + * @param PDO A PDO connection instance.
> + * @param array An array of settings.
> + */
> + public function initConnection(PDO $con, array $settings = array())
> + {
> + if(isset($settings[​'charset']['value'])​) {
> + $con->query('SET NAMES "' . $settings['charset']['value'] . '"');
> + }
> + parent::initConnection($con, $settings);
> + }
> +
> + /**
> * This method is used to ignore case.
> *
> * @param in The string to transform to upper case.
>
> --------------------​--------------------​--------------------​---------
> To unsubscribe, e-mail: cvs-unsubscribe@prop​el.tigris.org
> For additional commands, e-mail: cvs-help at propel dot tigris dot org
>
>

« Previous message in topic | 1 of 13 | Next message in topic »

Messages

Show all messages in topic

Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-01-14 22:03:31 PST
     Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Cameron Brunner <cameron dot brunner at gmail dot com> Cameron Brunner <cameron dot brunner at gmail dot com> 2007-01-14 22:17:07 PST
         Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-01-14 22:26:32 PST
             Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Cameron Brunner <cameron dot brunner at gmail dot com> Cameron Brunner <cameron dot brunner at gmail dot com> 2007-01-14 22:46:28 PST
                 Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Cameron Brunner <cameron dot brunner at gmail dot com> Cameron Brunner <cameron dot brunner at gmail dot com> 2007-01-14 23:50:36 PST
                     Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-01-14 23:54:56 PST
                         Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Cameron Brunner <cameron dot brunner at gmail dot com> Cameron Brunner <cameron dot brunner at gmail dot com> 2007-01-15 00:24:20 PST
                         Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Eric Fredj <eofredj at gmail dot com> Eric Fredj <eofredj at gmail dot com> 2007-01-15 00:28:19 PST
                             Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Eric Fredj <eofredj at gmail dot com> Eric Fredj <eofredj at gmail dot com> 2007-01-15 00:29:45 PST
                             Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> =?ISO-8859-1?Q?David_Z=FClke?= <dz at bitxtender dot com> 2007-01-15 00:34:13 PST
                                 Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Eric Fredj <eofredj at gmail dot com> Eric Fredj <eofredj at gmail dot com> 2007-01-15 10:16:12 PST
     Re: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter hlellelid Hans Lellelid 2007-01-15 15:26:51 PST
     RE: [propel-dev] Re: [propel-cvs] SVN update: r541 - in branches/1.3: generator/projects/bookstore runtime/classes/propel runtime/classes/propel/adapter Soenke Ruempler - NorthClick <soenke dot ruempler at northclick dot de> Soenke Ruempler - NorthClick <soenke dot ruempler at northclick dot de> 2007-01-16 02:11:24 PST
Messages per page: