CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • PDO Exceptions
Pages: [1]

Author Topic: PDO Exceptions  (Read 4531 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
PDO Exceptions
September 22, 2010, 08:50:52 pm
When running the unit tests I'm seeing a heap of these errors. PDO mysql does show up in phpinfo - any thoughts?

835) CRM_Pledge_BAO_PledgeTest::testRetrieveStringPledgeID
PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PD
OStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting
 the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

Also, do the unit tests get run before every . version release? I am getting some failures that look like 'real' fails but I assume the tests are run all the time & pass & it must be something on mine - e.g.


There were 4 failures:

1) api_v2_ActivityTest::testActivityCreate
Error message: Invalid Activity Status
Failed asserting that <integer:0> matches expected <integer:1>.


2) api_v2_ActivityTest::testActivityCreateCustom
Error message: Invalid Activity Status
Failed asserting that <integer:1> matches expected <integer:0>.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: PDO Exceptions
September 23, 2010, 06:00:59 am
Hey,

Didn't come over the error that you pasted before. Did you try setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute as they suggest?

As for failing tests, both are known. They are caused by caching and appear when running whole test suite (but not when running single tests) - they don't refer to regular CiviCRM functioning and/or regular API usage. I'm keeping them in such state because I want to fix the caching issue one day, it's just low priority. There was more of such errors, right now there should be only 4.

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PDO Exceptions
September 24, 2010, 04:30:12 pm
I'm trying to figure out how to do the PDO setting...
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: PDO Exceptions
November 09, 2010, 06:39:26 am
Wondering if this was resolved? I get this on windows but not on linux.

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: PDO Exceptions
November 09, 2010, 07:28:42 am
Hey,

Unfortunately, I don't have a windows machine to check it, so trying a bit blindly here. Something I would try first is to change tools/packages/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php line 81 from

$statement = $this->pdo->prepare($query);

to

$statement = $this->pdo->prepare($query, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));

and see what happens. And take it from there based on what blows up. :-)

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: PDO Exceptions
November 09, 2010, 02:24:01 pm
I get less errors. Still getting two of them from somewhere. I also tried setting it in DefaultDatabaseConnection where the connection attributes are set but no difference.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PDO Exceptions
November 09, 2010, 02:31:32 pm
re the errors the same? I'll fish out what I did once the boys brains are numbed by TV
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: PDO Exceptions
November 11, 2010, 02:41:31 pm
I'm getting some really weird stuff going on:

Current situation:

- With E_STRICT turned on, CiviUnitTestCase complains about not finding class CRM_Core_Config, but the line above it which is the require_once statement runs just fine. Removing the require line leads to a whole bunch of other errors, and moving the line to the top of the file outside the class definition works but then gives errors about the code in CRM_Core_Config (e.g. CRM_Utils_File::createDir called statically when it isn't static) and each one I fixed led to another one so I gave up on that. The code above the require_once line that says fixme might be relevant but as far as I can tell does nothing because $config is a local variable.

- Also why the error about the missing class comes through as an E_STRICT error (and fails silently if you don't have it set) is unknown. Seems more like a fatal error than a code style warning. So again something weird that PHP is doing.

- For the remaining PDO error that this thread started out about, the previous paragraphs happened because I was trying to find where it is being generated and haven't been able to yet. There is no backtrace (it's blank if you check it in the error handler).

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PDO Exceptions
November 11, 2010, 02:43:58 pm
HI,

I'll take another look at my set-up but one thing to watch out for (although hopefully patched now) is that the code was / is using hard coded unix separators rather than the SEPARATOR constant so paths that look fine may not be.

I will take a look when I figure out this silly report!
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: PDO Exceptions
November 11, 2010, 03:10:59 pm
Thanks.
In 3.3 the path separator seems to be generalized in the code. And it isn't an include_path issue.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: PDO Exceptions
January 04, 2011, 06:18:43 pm
This patch allows my windows machine to run the v2/ActivityTest suite (which was the main blocker I had.)  As you can see in the code running only one SQL clause at a time is the key. I don't think there are loads of places where SQL is run directly in the test suite. But I committed this in the API branch so not sure if that was the right thing to do

Quote
Index: phpunit/Utils.php
===================================================================
--- phpunit/Utils.php   (revision 31605)
+++ phpunit/Utils.php   (revision 31552)
@@ -49,8 +49,7 @@
     {
         try {
             $this->pdo = new PDO( "mysql:host={$host}",
-                                  $user, $pass,
-                                  array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true ));
+                                  $user, $pass );
         } catch ( PDOException $e ) {
             echo "Can't connect to MySQL server:" . PHP_EOL
                 . $e->getMessage() . PHP_EOL;
Index: phpunit/api/v2/ActivityTest.php
===================================================================
--- phpunit/api/v2/ActivityTest.php   (revision 31605)
+++ phpunit/api/v2/ActivityTest.php   (revision 31552)
@@ -363,10 +363,8 @@
                              . '/dataset/custom_group_activity_type.xml') );
 
         //  Drop and create table civicrm_value_activity_custom_9
-        $query = 'USE civicrm_tests_dev; ';
+        $query = 'USE civicrm_tests_dev; DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
         self::$utils->do_query( $query );
-        $query = 'DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
-        self::$utils->do_query( $query );     
         $group = new CRM_Core_DAO_CustomGroup();
         $group->extends = "Activity";
         $group->table_name = 'civicrm_value_activity_custom_9';
@@ -635,10 +633,8 @@
                              . '/dataset/custom_group_activity_type.xml') );
 
         //  Drop and create table civicrm_value_activity_custom_9
-        $query = 'USE civicrm_tests_dev; ';
+        $query = 'USE civicrm_tests_dev; DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
         self::$utils->do_query( $query );
-        $query = 'DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
-        self::$utils->do_query( $query ); 
         $group = new CRM_Core_DAO_CustomGroup();
         $group->extends = "Activity";
         $group->table_name = 'civicrm_value_activity_custom_9';
@@ -657,10 +653,7 @@
         CRM_Core_BAO_CustomField::createField( $customField, 'add' );
 
         //  Insert a test value into the new table
-        //  Insert a test value into the new table
-        $query = "USE civicrm_tests_dev; ";
-        self::$utils->do_query( $query );
-        $query = "INSERT INTO civicrm_value_activity_custom_9"
+        $query = "USE civicrm_tests_dev; INSERT INTO civicrm_value_activity_custom_9"
                . "( entity_id, activity_custom_11 )"
                . " VALUES ( 4,  'bite my test data' )";
         self::$utils->do_query( $query );
@@ -1018,10 +1011,8 @@
                              . '/dataset/custom_group_activity_type.xml') );
 
         //  Drop and create table civicrm_value_activity_custom_9
-        $query = 'USE civicrm_tests_dev;';
+        $query = 'USE civicrm_tests_dev; DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
         self::$utils->do_query( $query );
-        $query = 'DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
-        self::$utils->do_query( $query );
         $group = new CRM_Core_DAO_CustomGroup();
         $group->extends = "Activity";
         $group->table_name = 'civicrm_value_activity_custom_9';
Index: phpunit/CiviTest/CiviUnitTestCase.php
===================================================================
--- phpunit/CiviTest/CiviUnitTestCase.php   (revision 31605)
+++ phpunit/CiviTest/CiviUnitTestCase.php   (revision 31552)
@@ -136,14 +136,14 @@
         }
 
         self::$populateOnce = null;
-       
-        $queries = array( "DROP DATABASE IF EXISTS civicrm_tests_dev;",
-                          "CREATE DATABASE civicrm_tests_dev DEFAULT" .
-                          " CHARACTER SET utf8 COLLATE utf8_unicode_ci;",
-                                 "USE civicrm_tests_dev;",                               
-                          // SQL mode needs to be strict, that's our standard
-                          "SET SQL_MODE='STRICT_ALL_TABLES';" ,
-                          "SET global innodb_flush_log_at_trx_commit = 2;"
+
+            $queries = array( "DROP DATABASE IF EXISTS civicrm_tests_dev;",
+                              "CREATE DATABASE civicrm_tests_dev DEFAULT" .
+                              " CHARACTER SET utf8 COLLATE utf8_unicode_ci;",
+                              "USE civicrm_tests_dev;",
+                              // SQL mode needs to be strict, that's our standard
+                              "SET SQL_MODE='STRICT_ALL_TABLES';" .
+                              "set global innodb_flush_log_at_trx_commit = 2;"
                              );
             foreach( $queries as $query ) {
                 if ( self::$utils->do_query($query) === false ) {

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • PDO Exceptions

This forum was archived on 2017-11-26.