fixing the broken pdo driver in codeigniter 2.2.6

This commit is contained in:
hyung-hwan 2021-09-05 14:19:26 +00:00
parent c486fe664c
commit 64a0b15c54
8 changed files with 133 additions and 21 deletions

View File

@ -1,6 +1,6 @@
cfgdir=$(CFGDIR)
cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.a2ldap codepot.httpd
cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.sqlite codepot.a2ldap codepot.httpd
cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl
perldir=$(CFGDIR)/perl/Codepot

View File

@ -260,7 +260,7 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
wwwdir = @wwwdir@
cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.a2ldap codepot.httpd
cfg_DATA = codepot.ini codepot.mysql codepot.pgsql codepot.sqlite codepot.a2ldap codepot.httpd
cfg_SCRIPTS = start-commit pre-commit post-commit pre-revprop-change post-revprop-change cloc.pl
perldir = $(CFGDIR)/perl/Codepot
perl_SCRIPTS = perl/Codepot/AccessHandler.pm perl/Codepot/AuthenHandler.pm

View File

@ -11,24 +11,26 @@ default_site_name = "@PACKAGE@"
;------------------------------------------------------------------------------
; database settings
;
; database_driver: pdo, mysql, mysqli, postgre, oci8
; database_driver: mysql, mysqli, postgre, oci8, sqlite
;
; == PDO mysql ==
; database_hostname = "mysql:host=localhost;dbname=codepot"
; database_hostname = "localhost"
; database_port = ""
; database_username = "codepot"
; database_password = "codepot"
; database_name = ""
; database_driver = "pdo"
; database_name = "codepot"
; database_driver = "mysql"
; database_use_pdo = "yes"
; database_prefix = ""
;
; == PDO sqlite ==
; database_hostname = "sqlite:/var/lib/codepot/codepot.sqlite"
; database_hostname = "/var/lib/codepot/codepot.db"
; database_port = ""
; database_username = ""
; database_password = ""
; database_name = ""
; database_driver = "pdo"
; database_driver = "sqlite"
; database_use_pdo = "yes"
; database_prefix = ""
;
; == MySQL ==
@ -38,6 +40,7 @@ default_site_name = "@PACKAGE@"
; database_password = "codepot"
; database_name = "codepot"
; database_driver = "mysql"
; database_use_pdo = "no"
; database_prefix = ""
;
; == PostgresSQL ==
@ -47,6 +50,7 @@ default_site_name = "@PACKAGE@"
; database_password = "codepot"
; database_name = "codepot"
; database_driver = "postgre"
; database_use_pdo = "no"
; database_prefix = ""
;
; == Oracle
@ -56,6 +60,7 @@ default_site_name = "@PACKAGE@"
; database_password = "tiger"
; database_name = ""
; database_driver = "oci8"
; database_use_pdo = "no"
; database_prefix = "cpot_"
;------------------------------------------------------------------------------
database_hostname = "localhost"
@ -65,6 +70,7 @@ database_password = ""
database_name = ""
database_driver = ""
database_prefix = ""
database_use_pdo = "no"
database_store_gmt = "yes"
;------------------------------------------------------------------------------

View File

@ -24,13 +24,13 @@ sub get_config
}
my $config = {
database_hostname => $cfg->param ("database_hostname"),
database_port => $cfg->param ("database_port"),
database_username => $cfg->param ("database_username"),
database_password => $cfg->param ("database_password"),
database_name => $cfg->param ("database_name"),
database_driver => $cfg->param ("database_driver"),
database_prefix => $cfg->param ("database_prefix"),
database_hostname => $cfg->param("database_hostname"),
database_port => $cfg->param("database_port"),
database_username => $cfg->param("database_username"),
database_password => $cfg->param("database_password"),
database_name => $cfg->param("database_name"),
database_driver => $cfg->param("database_driver"),
database_prefix => $cfg->param("database_prefix"),
codepot_user_executor => $cfg->param("codepot_user_executor")
};

View File

@ -37,12 +37,12 @@
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = CODEPOT_DATABASE_HOSTNAME;
$db['default']['hostname'] = CODEPOT_DATABASE_REAL_HOSTNAME;
$db['default']['port'] = CODEPOT_DATABASE_PORT;
$db['default']['username'] = CODEPOT_DATABASE_USERNAME;
$db['default']['password'] = CODEPOT_DATABASE_PASSWORD;
$db['default']['database'] = CODEPOT_DATABASE_NAME;
$db['default']['dbdriver'] = CODEPOT_DATABASE_DRIVER;
$db['default']['dbdriver'] = CODEPOT_DATABASE_REAL_DRIVER;
$db['default']['dbprefix'] = CODEPOT_DATABASE_PREFIX;
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;

View File

@ -61,6 +61,7 @@ function load_ini ($file)
array ('database_password', 'string', ''),
array ('database_name', 'string', ''),
array ('database_driver', 'string', ''),
array ('database_use_pdo', 'boolean', FALSE),
array ('database_prefix', 'string', ''),
array ('database_store_gmt', 'boolean', FALSE),
@ -155,6 +156,38 @@ function load_ini ($file)
else define ($const, $x[2]);
}
if (CODEPOT_DATABASE_USE_PDO)
{
// override the hostname for PDO.
// this block isn't perfect as it handles translation for a few well known databases.
if (CODEPOT_DATABASE_DRIVER == "sqlite")
{
$hostname = sprintf("sqlite:%s", CODEPOT_DATABASE_HOSTNAME);
}
elseif (CODEPOT_DATABASE_DRIVER == "postgre")
{
$hostname = sprintf("pgsql:host=%s;port=%s;dbname=%s", CODEPOT_DATABASE_HOSTNAME, CODEPOT_DATABASE_PORT, CODEPOT_DATABASE_NAME);
}
elseif (CODEPOT_DATABASE_DRIVER == "mysqli")
{
$hostname = sprintf("mysql:host=%s;port=%s;dbname=%s", CODEPOT_DATABASE_HOSTNAME, CODEPOT_DATABASE_PORT, CODEPOT_DATABASE_NAME);
}
else
{
$hostname = sprintf("%s:host=%s;port=%s;dbname=%s", CODEPOT_DATABASE_DRIVER, CODEPOT_DATABASE_HOSTNAME, CODEPOT_DATABASE_PORT, CODEPOT_DATABASE_NAME);
}
define('CODEPOT_DATABASE_REAL_HOSTNAME', $hostname);
define('CODEPOT_DATABASE_REAL_DRIVER', 'pdo');
}
else
{
define('CODEPOT_DATABASE_REAL_HOSTNAME', CODEPOT_DATABASE_HOSTNAME);
define('CODEPOT_DATABASE_REAL_DRIVER', CODEPOT_DATABASE_DRIVER);
}
return TRUE;
}

View File

@ -14,6 +14,78 @@
* @filesource
*/
// HYUNG-HWAN:
// hack against the CodeIgniter's PDO driver bug.
// The main driver calls PDOStatement::fetchAll() multiple times over the same instance.
// The method returns the empty result set on the second and later calls.
// Create this wrapper to cache the result on the first call and return the stored result on later calls.
class CI_DB_pdo_statement_wrapper
{
private $actual_pdo_statement;
private $ever_fetched = false;
private $stored_result;
private $cursor = -1;
public function __construct ($pdo_statement)
{
$this->actual_pdo_statement = $pdo_statement;
$this->ever_fetched = false;
$this->cursor = 0;
}
public function fetchAll ()
{
if (!$this->ever_fetched)
{
$this->ever_fetched = true;
$this->stored_result = $this->actual_pdo_statement->fetchAll(PDO::FETCH_ASSOC);
}
return $this->stored_result;
}
public function fetchObject()
{
if ($this->ever_fetched)
{
if ($this->cursor >= count($this->stored_result)) return false;
$row = $this->stored_result[$this->cursor];
$this->cursor++;
$obj = new stdClass();
foreach ($row as $k => $v)
{
//if (!is_numeric($k)) $obj->$k = $row[$k];
$obj->$k = $row[$k];
}
return $obj;
}
return $this->actual_pdo_statement->fetchObject();
}
public function fetchAssoc ()
{
if ($this->ever_fetched)
{
if ($this->cursor >= count($this->stored_result)) return false;
$tmp = $this->stored_result[$this->cursor];
$this->cursor++;
return $tmp;
}
return $this->actual_pdo_statement->fetch(PDO::FETCH_ASSOC);
}
public function __call ($method_name, $arguments)
{
$callable = [$this->actual_pdo_statement, $method_name];
return call_user_func_array($callable, $arguments);
}
};
// ------------------------------------------------------------------------
/**
@ -190,7 +262,7 @@ class CI_DB_pdo_driver extends CI_DB {
function _execute($sql)
{
$sql = $this->_prep_query($sql);
$result_id = $this->conn_id->prepare($sql);
$result_id = new CI_DB_pdo_statement_wrapper($this->conn_id->prepare($sql));
if (is_object($result_id) && $result_id->execute())
{
@ -809,4 +881,4 @@ class CI_DB_pdo_driver extends CI_DB {
/* End of file pdo_driver.php */
/* Location: ./system/database/drivers/pdo/pdo_driver.php */
/* Location: ./system/database/drivers/pdo/pdo_driver.php */

View File

@ -159,7 +159,8 @@ class CI_DB_pdo_result extends CI_DB_result {
*/
function _fetch_assoc()
{
return $this->result_id->fetch(PDO::FETCH_ASSOC);
//return $this->result_id->fetch(PDO::FETCH_ASSOC);
return $this->result_id->fetchAssoc(); // HYUNG-HWAN: available in CI_DB_pdo_statement_wrapper only
}
// --------------------------------------------------------------------
@ -181,4 +182,4 @@ class CI_DB_pdo_result extends CI_DB_result {
/* End of file pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */