Permalink
Browse files

Merge branch 'jelix-1.4.x'

  • Loading branch information...
laurentj committed Nov 13, 2012
2 parents 736b82d + bd8bc92 commit 27a3b08e3a176a9648a087408adb058e08e2b910
@@ -62,8 +62,8 @@ public function run(){
$this->createDir($path.$locale_filename_fr);
$locale_filename_fr.=strtolower($this->_parameters['form']).'.UTF-8.properties';
- $locale_filename_en = $path.'locales/en_US/';
- $this->createDir($locale_filename_en);
+ $locale_filename_en = 'locales/en_US/';
+ $this->createDir($path.$locale_filename_en);
$locale_filename_en.=strtolower($this->_parameters['form']).'.UTF-8.properties';
$submit="\n\n<submit ref=\"_submit\">\n\t<label locale='".$locale_base."ok' />\n</submit>";
@@ -5,14 +5,14 @@
* @author Gérald Croes, Laurent Jouanneau
* @contributor Laurent Jouanneau
* @contributor Florian Lonqueu-Brochard
-* @copyright 2001-2005 CopixTeam, 2005-2010 Laurent Jouanneau
+* @copyright 2001-2005 CopixTeam, 2005-2012 Laurent Jouanneau
* @copyright 2012 Florian Lonqueu-Brochard
* @link http://www.jelix.org
* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
*/
/**
- * Couche d'encapsulation des resultset mysql.
+ * Object to fetch result, wrapping the underlaying result object of mysqli
* @package jelix
* @subpackage db_driver
*/
@@ -57,3 +57,42 @@ public function execute($parameters=null)
{throw new jException('jelix~db.error.feature.unsupported', array('mysql','execute')); }
}
+
+/**
+ * Object to fetch result, wrapping a statement object of mysqli,
+ * for installation where mysqlnd is not used
+ * @package jelix
+ * @subpackage db_driver
+ */
+class mysqliDbStmtResultSet extends mysqliDbResultSet {
+
+ protected $resultObject = null;
+
+ function __construct ($result) {
+ parent::__construct($result);
+ //this call to store_result() will buffer all results but is necessary for num_rows to have
+ //its real value and thus for dbresultset's ->rowCount() to work fine :
+ $result->store_result();
+
+ // we have a statement, so no fetch_object method
+ // so we will create results object. We need to bind result.
+ $meta = $result->result_metadata();
+
+ $this->resultObject = new stdClass();
+
+ while($field = $meta->fetch_field()) {
+ $this->resultObject->{$field->name} = null;
+ $variables[] = & $this->resultObject->{$field->name}; // pass by reference
+ }
+ call_user_func_array(array($result, 'bind_result'), $variables);
+ $meta->close();
+ }
+
+ protected function _fetch () {
+ if (!$this->_idResult->fetch())
+ return false;
+ $result = clone $this->resultObject;
+ return $result;
+ }
+
+}
@@ -3,7 +3,8 @@
* @package jelix
* @subpackage db_driver
* @author Florian Lonqueu-Brochard
-* @copyright 2012 Florian Lonqueu-Brochard
+* @contributor Laurent Jouanneau
+* @copyright 2012 Florian Lonqueu-Brochard, 2012 Laurent Jouanneau
* @link http://www.jelix.org
* @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
*/
@@ -29,10 +30,7 @@ public function execute(){
//with the MySQL native driver - mysqlnd (by default in php 5.3.0)
$res = new mysqliDbResultSet($this->_stmt->get_result());
} else {
- //this call to store_result() will buffer all results but is necessary for num_rows to have
- //its real value and thus for dbresultset's ->rowCount() to work fine :
- $this->_stmt->store_result();
- $res = new mysqliDbResultSet($this->_stmt);
+ $res = new mysqliDbStmtResultSet($this->_stmt);
}
}
catch(Exception $e){
@@ -98,9 +98,8 @@ function testPreparedQueries(){
$this->assertTableHasNRecords('labels_test', 3);
$stmt = null;
-
//SELECT
- $stmt = $cnx->prepare('SELECT * FROM labels_test WHERE lang = ?');
+ $stmt = $cnx->prepare('SELECT `key`,`lang` ,`label` FROM labels_test WHERE lang = ? ORDER BY `key` asc');
$this->assertTrue($stmt instanceof mysqliDbStatement);
$lang = 'fr';
$bind = $stmt->bindParam('s', $lang);
@@ -109,6 +108,11 @@ function testPreparedQueries(){
$res = $stmt->execute();
$this->assertTrue($res instanceof mysqliDbResultSet);
$this->assertEqual($res->rowCount(), 2);
+
+ $result = $res->fetch();
+ $this->assertEqual('11', $result->key);
+ $this->assertEqual('fr', $result->lang);
+ $this->assertEqual('France', $result->label);
}

0 comments on commit 27a3b08

Please sign in to comment.