# patched codeigniter's oci8 driver to cater for codepot's usecasees.

# renamed user to user_account
# changed some files to support oracle
This commit is contained in:
hyung-hwan 2015-04-29 14:31:15 +00:00
parent 21b84fe0cd
commit 3e00b1023e
17 changed files with 281 additions and 97 deletions

View File

@ -14,6 +14,7 @@ UPGRADING FROM 0.2.0
mysql> ALTER TABLE user_settings CHANGE code_hide_details code_hide_metadata CHAR(1) NOT NULL; mysql> ALTER TABLE user_settings CHANGE code_hide_details code_hide_metadata CHAR(1) NOT NULL;
mysql> ALTER TABLE site ADD COLUMN(summary VARCHAR(255) NOT NULL); mysql> ALTER TABLE site ADD COLUMN(summary VARCHAR(255) NOT NULL);
mysql> RENAME TABLE user TO user_account;
INSTALLATION ON CENTOS INSTALLATION ON CENTOS

View File

@ -11,7 +11,34 @@ default_site_name = "@PACKAGE@"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
; database settings ; database settings
; ;
; database_driver: mysql for MySQL, postgre for PostgreSQL ; database_driver: mysql, mysqli, postgre, oci8
;
; == MySQL ==
; database_hostname = "localhost"
; database_port = ""
; database_username = "codepot"
; database_password = "codepot"
; database_name = "codepot"
; database_driver = "mysql"
; database_prefix = ""
;
; == PostgresSQL ==
; database_hostname = ""
; database_port = ""
; database_username = "codepot"
; database_password = "codepot"
; database_name = "codepot"
; database_driver = "postgre"
; database_prefix = ""
;
; == Oracle
; database_hostname = "(DESCRIPTION=(ADDRESS=(COMMUNITY=tcp.world)(PROTOCOL=TCP)(HOST=192.168.1.126)(PORT=1521))(CONNECT_DATA=(SID=ORCL)))"
; database_port = ""
; database_username = "scott"
; database_password = "tiger"
; database_name = ""
; database_driver = "oci8"
; database_prefix = "cpot_"
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
database_hostname = "localhost" database_hostname = "localhost"
database_port = "" database_port = ""

View File

@ -125,7 +125,7 @@ CREATE TABLE issue_change (
status VARCHAR(32) NOT NULL, status VARCHAR(32) NOT NULL,
owner VARCHAR(255) NOT NULL, owner VARCHAR(255) NOT NULL,
priority VARCHAR(32) NOT NULL, priority VARCHAR(32) NOT NULL,
comment TEXT NOT NULL, comment TEXT NOT NULL,
updatedon DATETIME NOT NULL, updatedon DATETIME NOT NULL,
updatedby VARCHAR(32) NOT NULL, updatedby VARCHAR(32) NOT NULL,
@ -183,7 +183,7 @@ CREATE TABLE code_review (
projectid VARCHAR(32) NOT NULL, projectid VARCHAR(32) NOT NULL,
rev BIGINT NOT NULL, rev BIGINT NOT NULL,
sno BIGINT NOT NULL, sno BIGINT NOT NULL,
comment TEXT NOT NULL, comment TEXT NOT NULL,
createdon DATETIME NOT NULL, createdon DATETIME NOT NULL,
createdby VARCHAR(32) NOT NULL, createdby VARCHAR(32) NOT NULL,
@ -215,7 +215,7 @@ CREATE TABLE user_settings (
icon_name VARCHAR(255) UNIQUE NULL icon_name VARCHAR(255) UNIQUE NULL
) charset=utf8 engine=InnoDB; ) charset=utf8 engine=InnoDB;
CREATE TABLE user ( CREATE TABLE user_account (
userid VARCHAR(32) PRIMARY KEY, userid VARCHAR(32) PRIMARY KEY,
passwd VARCHAR(255) NOT NULL, passwd VARCHAR(255) NOT NULL,
email VARCHAR(255), email VARCHAR(255),

View File

@ -9,7 +9,7 @@
-- --
-- --
-- DROP SEQUENCE "cpot_log_id_seq"; -- DROP SEQUENCE "cpot_log_id_seq";
-- DROP TABLE "cpot_user"; -- DROP TABLE "cpot_user_account";
-- DROP TABLE "cpot_user_settings"; -- DROP TABLE "cpot_user_settings";
-- DROP TABLE "cpot_log"; -- DROP TABLE "cpot_log";
-- DROP TABLE "cpot_code_review"; -- DROP TABLE "cpot_code_review";
@ -202,7 +202,7 @@ CREATE TABLE "cpot_user_settings" (
"icon_name" VARCHAR(255) UNIQUE NULL "icon_name" VARCHAR(255) UNIQUE NULL
); );
CREATE TABLE "cpot_user" ( CREATE TABLE "cpot_user_account" (
"userid" VARCHAR(32) PRIMARY KEY, "userid" VARCHAR(32) PRIMARY KEY,
"passwd" VARCHAR(255) NOT NULL, "passwd" VARCHAR(255) NOT NULL,
"email" VARCHAR(255), "email" VARCHAR(255),

View File

@ -143,7 +143,7 @@ CREATE TABLE issue_change (
status VARCHAR(32) NOT NULL, status VARCHAR(32) NOT NULL,
owner VARCHAR(255) NOT NULL, owner VARCHAR(255) NOT NULL,
priority VARCHAR(32) NOT NULL, priority VARCHAR(32) NOT NULL,
comment TEXT NOT NULL, comment TEXT NOT NULL,
updatedon TIMESTAMP NOT NULL, updatedon TIMESTAMP NOT NULL,
updatedby VARCHAR(32) NOT NULL, updatedby VARCHAR(32) NOT NULL,
@ -203,7 +203,7 @@ CREATE TABLE code_review (
projectid VARCHAR(32) NOT NULL, projectid VARCHAR(32) NOT NULL,
rev BIGINT NOT NULL, rev BIGINT NOT NULL,
sno BIGINT NOT NULL, sno BIGINT NOT NULL,
comment TEXT NOT NULL, comment TEXT NOT NULL,
createdon TIMESTAMP NOT NULL, createdon TIMESTAMP NOT NULL,
createdby VARCHAR(32) NOT NULL, createdby VARCHAR(32) NOT NULL,
@ -236,7 +236,7 @@ CREATE TABLE user_settings (
icon_name VARCHAR(255) UNIQUE NULL icon_name VARCHAR(255) UNIQUE NULL
); );
CREATE TABLE "user" ( CREATE TABLE user_account (
userid VARCHAR(32) PRIMARY KEY, userid VARCHAR(32) PRIMARY KEY,
passwd VARCHAR(255) NOT NULL, passwd VARCHAR(255) NOT NULL,
email VARCHAR(255), email VARCHAR(255),

View File

@ -162,15 +162,9 @@ sub authenticate_ldap
sub authenticate_database sub authenticate_database
{ {
my ($dbh, $prefix, $userid, $password, $driver) = @_; my ($dbh, $prefix, $userid, $password, $qc) = @_;
my $user_table_name = "${prefix}user"; my $query = $dbh->prepare ("SELECT ${qc}userid${qc},${qc}passwd${qc} FROM ${qc}${prefix}user_account${qc} WHERE ${qc}userid${qc}=? and ${qc}enabled${qc}='Y'");
if ($driver eq 'postgre' && length($prefix) <= 0)
{
$user_table_name = '"user"';
}
my $query = $dbh->prepare ("SELECT userid,passwd FROM ${user_table_name} WHERE userid=? and enabled='Y'");
if (!$query || !$query->execute ($userid)) if (!$query || !$query->execute ($userid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -201,15 +195,30 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -224,9 +233,9 @@ sub close_database
sub is_project_member sub is_project_member
{ {
my ($dbh, $prefix, $projectid, $userid) = @_; my ($dbh, $prefix, $projectid, $userid, $qc) = @_;
my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); my $query = $dbh->prepare ("SELECT ${qc}projectid${qc} FROM ${qc}${prefix}project_membership${qc} WHERE ${qc}userid${qc}=? AND ${qc}projectid${qc}=?");
if (!$query || !$query->execute ($userid, $projectid)) if (!$query || !$query->execute ($userid, $projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -239,9 +248,9 @@ sub is_project_member
sub is_project_public sub is_project_public
{ {
my ($dbh, $prefix, $projectid) = @_; my ($dbh, $prefix, $projectid, $qc) = @_;
my $query = $dbh->prepare ("SELECT public FROM ${prefix}project WHERE id=?"); my $query = $dbh->prepare ("SELECT ${qc}public${qc} FROM ${qc}${prefix}project${qc} WHERE ${qc}id${qc}=?");
if (!$query || !$query->execute ($projectid)) if (!$query || !$query->execute ($projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -275,6 +284,9 @@ sub __handler
my $member = undef; my $member = undef;
my $errmsg = undef; my $errmsg = undef;
my $qc = '';
if ($cfg->{database_driver} eq 'oci8') { $qc = '"'; }
if ($r->proxyreq() == Apache2::Const::PROXYREQ_PROXY) if ($r->proxyreq() == Apache2::Const::PROXYREQ_PROXY)
{ {
$author = $r->headers_in->{'Proxy-Authorization'}; $author = $r->headers_in->{'Proxy-Authorization'};
@ -301,7 +313,7 @@ sub __handler
if ($is_method_r) if ($is_method_r)
{ {
($public, $errmsg) = is_project_public ($dbh, $cfg->{database_prefix}, $repo); ($public, $errmsg) = is_project_public ($dbh, $cfg->{database_prefix}, $repo, $qc);
if ($public <= -1) if ($public <= -1)
{ {
# failed to contact the authentication server # failed to contact the authentication server
@ -326,7 +338,7 @@ sub __handler
elsif ($cfg->{login_model} eq 'DbLoginModel') elsif ($cfg->{login_model} eq 'DbLoginModel')
{ {
($auth, $errmsg) = authenticate_database ( ($auth, $errmsg) = authenticate_database (
$dbh, $cfg->{database_prefix}, $userid, $password, $cfg->{database_driver}); $dbh, $cfg->{database_prefix}, $userid, $password, $qc);
if ($auth <= -1) if ($auth <= -1)
{ {
$r->log_error ("Database error - $errmsg"); $r->log_error ("Database error - $errmsg");
@ -352,7 +364,7 @@ sub __handler
return Apache2::Const::OK; return Apache2::Const::OK;
} }
($member, $errmsg) = is_project_member ($dbh, $cfg->{database_prefix}, $repo, $userid); ($member, $errmsg) = is_project_member ($dbh, $cfg->{database_prefix}, $repo, $userid, $qc);
if ($member <= -1) if ($member <= -1)
{ {
$r->log_error ("Cannot check project membership - $errmsg"); $r->log_error ("Cannot check project membership - $errmsg");

View File

@ -12,6 +12,8 @@ my $REPO = $ARGV[0];
my $REPOBASE = basename($REPO); my $REPOBASE = basename($REPO);
my $REV = $ARGV[1]; my $REV = $ARGV[1];
my $QC = '';
sub get_config sub get_config
{ {
my $cfg = new Config::Simple(); my $cfg = new Config::Simple();
@ -44,15 +46,31 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -75,12 +93,21 @@ sub write_commit_log
#| 895 | code | codepot | svn,codepot,72 | 2011-10-10 14:26:43 | commit | hyunghwan.chung | #| 895 | code | codepot | svn,codepot,72 | 2011-10-10 14:26:43 | commit | hyunghwan.chung |
my $message = "svn,$projectid,$revision"; my $message = "svn,$projectid,$revision";
my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime());
# the PHP side is executing ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF.
# do i have to do it here or use the database time (CURRENT_TIMESTAMP) instead?
# make sure that you have the same time between the app server and the data server.
# to minize side-effect of using the time of data server.
#my $createdon = strftime ('%Y-%m-%d %H:%M:%S', localtime());
$dbh->begin_work (); $dbh->begin_work ();
my $query = $dbh->prepare ("INSERT INTO ${prefix}log (type,projectid,message,createdon,action,userid) VALUES (?,?,?,?,?,?)"); #my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,?,?,?)");
if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid)) #if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'commit', $userid))
my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,CURRENT_TIMESTAMP,?,?)");
if (!$query || !$query->execute ('code', $projectid, $message, 'commit', $userid))
{ {
my $errstr = $dbh->errstr(); my $errstr = $dbh->errstr();
$query->finish (); $query->finish ();

View File

@ -15,6 +15,8 @@ my $USER = $ARGV[2];
my $PROPNAME = $ARGV[3]; my $PROPNAME = $ARGV[3];
my $ACTION = $ARGV[4]; my $ACTION = $ARGV[4];
my $QC = '';
# [STDIN] PROPVAL ** the old property value is passed via STDIN. # [STDIN] PROPVAL ** the old property value is passed via STDIN.
sub get_config sub get_config
@ -49,15 +51,31 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -84,7 +102,7 @@ sub write_revprop_change_log
$dbh->begin_work (); $dbh->begin_work ();
my $query = $dbh->prepare ("INSERT INTO ${prefix}log (type,projectid,message,createdon,action,userid) VALUES (?,?,?,?,?,?)"); my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}log${QC} (${QC}type${QC},${QC}projectid${QC},${QC}message${QC},${QC}createdon${QC},${QC}action${QC},${QC}userid${QC}) VALUES (?,?,?,?,?,?)");
if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'revpropchange', $userid)) if (!$query || !$query->execute ('code', $projectid, $message, $createdon, 'revpropchange', $userid))
{ {
my $errstr = $dbh->errstr(); my $errstr = $dbh->errstr();

View File

@ -15,6 +15,8 @@ my $REPOFS = $ARGV[0];
my $REPOBASE = basename($REPOFS); my $REPOBASE = basename($REPOFS);
my $TRANSACTION = $ARGV[1]; my $TRANSACTION = $ARGV[1];
my $QC = '';
my %SVN_ACTIONS = my %SVN_ACTIONS =
( (
'A ' => 'add', 'A ' => 'add',
@ -69,15 +71,31 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -94,7 +112,7 @@ sub is_project_member
{ {
my ($dbh, $prefix, $projectid, $userid) = @_; my ($dbh, $prefix, $projectid, $userid) = @_;
my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?");
if (!$query || !$query->execute ($userid, $projectid)) if (!$query || !$query->execute ($userid, $projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -109,7 +127,7 @@ sub is_project_commitable
{ {
my ($dbh, $prefix, $projectid) = @_; my ($dbh, $prefix, $projectid) = @_;
my $query = $dbh->prepare ("SELECT commitable FROM ${prefix}project WHERE id=?"); my $query = $dbh->prepare ("SELECT ${QC}commitable${QC} FROM ${QC}${prefix}project${QC} WHERE ${QC}id${QC}=?");
if (!$query || !$query->execute ($projectid)) if (!$query || !$query->execute ($projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());

View File

@ -18,6 +18,8 @@ my $USER = $ARGV[2];
my $PROPNAME = $ARGV[3]; my $PROPNAME = $ARGV[3];
my $ACTION = $ARGV[4]; my $ACTION = $ARGV[4];
my $QC = '';
sub get_config sub get_config
{ {
my $cfg = new Config::Simple(); my $cfg = new Config::Simple();
@ -52,15 +54,31 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -77,7 +95,7 @@ sub is_project_member
{ {
my ($dbh, $prefix, $projectid, $userid) = @_; my ($dbh, $prefix, $projectid, $userid) = @_;
my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?");
if (!$query || !$query->execute ($userid, $projectid)) if (!$query || !$query->execute ($userid, $projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());

View File

@ -10,6 +10,8 @@ my $CFG_FILE = '@CFGDIR@/codepot.ini';
my $REPOBASE = basename($ARGV[0]); my $REPOBASE = basename($ARGV[0]);
my $USER = $ARGV[1]; my $USER = $ARGV[1];
my $QC = '';
sub get_config sub get_config
{ {
my $cfg = new Config::Simple(); my $cfg = new Config::Simple();
@ -42,15 +44,31 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
if ($dbtype eq 'postgre') { $dbtype = 'Pg'; } if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
my $dbstr = "DBI:$dbtype:database=$dbname;"; my $dbstr;
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; } my $dbuser;
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
}
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -67,7 +85,7 @@ sub is_project_member
{ {
my ($dbh, $prefix, $projectid, $userid) = @_; my ($dbh, $prefix, $projectid, $userid) = @_;
my $query = $dbh->prepare ("SELECT projectid FROM ${prefix}project_membership WHERE userid=? AND projectid=?"); my $query = $dbh->prepare ("SELECT ${QC}projectid${QC} FROM ${QC}${prefix}project_membership${QC} WHERE ${QC}userid${QC}=? AND ${QC}projectid${QC}=?");
if (!$query || !$query->execute ($userid, $projectid)) if (!$query || !$query->execute ($userid, $projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -82,7 +100,7 @@ sub is_project_commitable
{ {
my ($dbh, $prefix, $projectid) = @_; my ($dbh, $prefix, $projectid) = @_;
my $query = $dbh->prepare ("SELECT commitable FROM ${prefix}project WHERE id=?"); my $query = $dbh->prepare ("SELECT ${QC}commitable${QC} FROM ${QC}${prefix}project${QC} WHERE ${QC}id${QC}=?");
if (!$query || !$query->execute ($projectid)) if (!$query || !$query->execute ($projectid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());

View File

@ -12,7 +12,7 @@ use Digest::SHA1 qw (sha1_hex);
my $CFG_FILE = '@CFGDIR@/codepot.ini'; my $CFG_FILE = '@CFGDIR@/codepot.ini';
my $USER_TABLE_NAME = 'user'; my $QC = '';
sub get_config sub get_config
{ {
@ -48,23 +48,32 @@ sub open_database
my $dbport = $cfg->{database_port}; my $dbport = $cfg->{database_port};
my $dbprefix = $cfg->{database_prefix}; my $dbprefix = $cfg->{database_prefix};
if ($dbtype eq 'postgre') if ($dbtype eq 'postgre') { $dbtype = 'Pg'; }
{ elsif ($dbtype eq 'oci8') { $dbtype = 'Oracle'; }
$dbtype = 'Pg'; elsif ($dbtype eq 'mysqli') { $dbtype = 'mysql'; }
# in postgresql, 'user' is a reserved word. my $dbstr;
# it requires quotes for the word to be used as a normal word my $dbuser;
if (length($dbprefix) <= 0) { $USER_TABLE_NAME = '"user"'; } my $dbpass;
if ($dbtype eq 'Oracle')
{
$QC = '"';
$dbstr = "DBI:$dbtype:";
$dbuser = $cfg->{database_username} . '/' . $cfg->{database_password} . '@' . $dbhost;
$dbpass = '';
}
else
{
$dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
$dbuser = $cfg->{database_username};
$dbpass = $cfg->{database_password};
} }
my $dbstr = "DBI:$dbtype:database=$dbname;";
if (length($dbhost) > 0) { $dbstr .= "host=$dbhost;"; }
if (length($dbport) > 0) { $dbstr .= "port=$dbport;"; }
my $dbh = DBI->connect( my $dbh = DBI->connect(
$dbstr, $dbstr, $dbuser, $dbpass,
$cfg->{database_username},
$cfg->{database_password},
{ RaiseError => 0, PrintError => 0, AutoCommit => 0 } { RaiseError => 0, PrintError => 0, AutoCommit => 0 }
); );
@ -104,7 +113,7 @@ sub authenticate_database
{ {
my ($dbh, $prefix, $userid, $password) = @_; my ($dbh, $prefix, $userid, $password) = @_;
my $query = $dbh->prepare ("SELECT userid,passwd FROM ${prefix}${USER_TABLE_NAME}} WHERE userid=? and enabled='N'"); my $query = $dbh->prepare ("SELECT ${QC}userid${QC},${QC}passwd${QC} FROM ${QC}${prefix}user_account${QC} WHERE ${QC}userid${QC}=? and ${QC}enabled${QC}='N'");
if (!$query || !$query->execute ($userid)) if (!$query || !$query->execute ($userid))
{ {
return (-1, $dbh->errstr()); return (-1, $dbh->errstr());
@ -136,7 +145,7 @@ sub add_user
$dbh->begin_work (); $dbh->begin_work ();
my $query = $dbh->prepare ("INSERT INTO ${prefix}${USER_TABLE_NAME} (userid,passwd,email,enabled) VALUES (?, ?, ?, ?)"); my $query = $dbh->prepare ("INSERT INTO ${QC}${prefix}user_account${QC} (${QC}userid${QC},${QC}passwd${QC},${QC}email${QC},${QC}enabled${QC}) VALUES (?, ?, ?, ?)");
if (!$query || !$query->execute ($userid, $fmt_pw, $email, 'N')) if (!$query || !$query->execute ($userid, $fmt_pw, $email, 'N'))
{ {
my $errstr = $dbh->errstr(); my $errstr = $dbh->errstr();
@ -156,7 +165,7 @@ sub delete_user
$dbh->begin_work (); $dbh->begin_work ();
my $query = $dbh->prepare ("DELETE FROM ${prefix}${USER_TABLE_NAME} WHERE userid=?"); my $query = $dbh->prepare ("DELETE FROM ${QC}${prefix}user_account${QC} WHERE ${QC}userid${QC}=?");
if (!$query || !$query->execute ($userid) || $query->rows() <= 0) if (!$query || !$query->execute ($userid) || $query->rows() <= 0)
{ {
my $errstr = $dbh->errstr(); my $errstr = $dbh->errstr();
@ -176,7 +185,7 @@ sub toggle_user
$dbh->begin_work (); $dbh->begin_work ();
my $query = $dbh->prepare ("UPDATE ${prefix}${USER_TABLE_NAME} SET enabled=? WHERE userid=?"); my $query = $dbh->prepare ("UPDATE ${QC}${prefix}user_account${QC} SET ${QC}enabled${QC}=? WHERE ${QC}userid${QC}=?");
if (!$query || !$query->execute ($enabled, $userid) || $query->rows() <= 0) if (!$query || !$query->execute ($enabled, $userid) || $query->rows() <= 0)
{ {
my $errstr = $dbh->errstr(); my $errstr = $dbh->errstr();

View File

@ -41,7 +41,7 @@ class DbLoginModel extends LoginModel
$this->db->select ('userid,passwd,email'); $this->db->select ('userid,passwd,email');
$this->db->where ('userid', $userid); $this->db->where ('userid', $userid);
$this->db->where ('enabled', 'Y'); $this->db->where ('enabled', 'Y');
$query = $this->db->get ('user'); $query = $this->db->get ('user_account');
if ($this->db->trans_status() == FALSE) if ($this->db->trans_status() == FALSE)
{ {
@ -64,7 +64,7 @@ class DbLoginModel extends LoginModel
// the last 10 characters are the salt. // the last 10 characters are the salt.
$hexsalt = substr ($user->passwd, -10); $hexsalt = substr ($user->passwd, -10);
$binsalt = pack('H*' , $hexsalt); $binsalt = pack('H*' , $hexsalt);
if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0) return FALSE; if (strcmp ($this->format_password_with_salt($passwd,$binsalt),$user->passwd) != 0) return FALSE;
return parent::authenticate ($userid, $user->passwd, $user->email); return parent::authenticate ($userid, $user->passwd, $user->email);
@ -77,7 +77,7 @@ class DbLoginModel extends LoginModel
$this->db->where ('userid', $userid); $this->db->where ('userid', $userid);
$this->db->set ('passwd', format_password($passwd,5)); $this->db->set ('passwd', format_password($passwd,5));
$this->db->update ('user'); $this->db->update ('user_account');
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)
{ {

View File

@ -23,7 +23,7 @@ class LogModel extends Model
if ($userid != '') $this->db->where ('userid', $userid); if ($userid != '') $this->db->where ('userid', $userid);
$this->db->select ('count(id) as count'); $this->db->select ('count(*) as count');
$query = $this->db->get ('log'); $query = $this->db->get ('log');
if ($this->db->trans_status() === FALSE) if ($this->db->trans_status() === FALSE)
{ {
@ -33,7 +33,8 @@ class LogModel extends Model
$result = $query->result(); $result = $query->result();
$num = empty($result)? 0: $result[0]->count; $num = empty($result)? 0:
isset($result[0]->COUNT)? $result[0]->COUNT: $result[0]->count;
$this->db->trans_complete (); $this->db->trans_complete ();
if ($this->db->trans_status() === FALSE) return FALSE; if ($this->db->trans_status() === FALSE) return FALSE;

View File

@ -149,12 +149,25 @@ class CI_DB_driver {
return FALSE; return FALSE;
} }
return TRUE; // HYUNG-HWAN
//return TRUE;
// END HYUNG-HWAN
} }
} }
// HYUNG-HWAN
$this->db_post_initialize ();
// END HYUNG-HWAN
return TRUE; return TRUE;
} }
// HYUNG-HWAN
function db_post_initialize ()
{
return TRUE;
}
// END HYUNG-HWAN
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -1363,4 +1376,4 @@ class CI_DB_driver {
/* End of file DB_driver.php */ /* End of file DB_driver.php */
/* Location: ./system/database/DB_driver.php */ /* Location: ./system/database/DB_driver.php */

View File

@ -139,6 +139,13 @@ class CI_DB_oci8_driver extends CI_DB {
// @todo - add support if needed // @todo - add support if needed
return TRUE; return TRUE;
} }
// HYUNG-HWAN
function db_post_initialize ()
{
$this->query ("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'");
}
// END HYUNG-HWAN
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -777,4 +784,4 @@ class CI_DB_oci8_driver extends CI_DB {
/* End of file oci8_driver.php */ /* End of file oci8_driver.php */
/* Location: ./system/database/drivers/oci8/oci8_driver.php */ /* Location: ./system/database/drivers/oci8/oci8_driver.php */

View File

@ -174,7 +174,22 @@ class CI_DB_oci8_result extends CI_DB_result {
{ {
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id; $id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
return @oci_fetch_object($id); // BEGIN HYUNG-HWAN
//return @oci_fetch_object($id);
$x = @oci_fetch_object($id);
if (is_object($x))
{
foreach ($x as $k => $v)
{
if (is_object($v) && get_class($v) == 'OCI-Lob')
{
$x->$k = $v->load();
}
}
}
return $x;
// END HYUNG-HWAN
} }
// If PHP 4 is being used we have to build our own result // If PHP 4 is being used we have to build our own result
@ -246,4 +261,4 @@ class CI_DB_oci8_result extends CI_DB_result {
/* End of file oci8_result.php */ /* End of file oci8_result.php */
/* Location: ./system/database/drivers/oci8/oci8_result.php */ /* Location: ./system/database/drivers/oci8/oci8_result.php */