Skip to content

Commit

Permalink
Updated code with docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamculp committed Nov 5, 2014
1 parent 79f64b4 commit 634a15d
Show file tree
Hide file tree
Showing 9 changed files with 2,753 additions and 1,223 deletions.
1,024 changes: 565 additions & 459 deletions ToolkitApi/CW/cw.php

Large diffs are not rendered by default.

245 changes: 189 additions & 56 deletions ToolkitApi/CW/cwclasses.php

Large diffs are not rendered by default.

97 changes: 77 additions & 20 deletions ToolkitApi/Db2supp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
<?php
/**
* Class db2supp
*
* @todo define common transport class/interface extended/implemented by all transports
*
* @package ToolkitApi
*/
class db2supp {

// TODO define common transport class/interface extended/implemented by all transports
Expand All @@ -7,7 +14,15 @@ class db2supp {
private $last_errorcode = ''; // SQL State
private $last_errormsg = ''; // SQL Code with message

// 'persistent' is one option
/**
* @todo Throw in your "transport/adapter" framework for a real OO look and feel ....
* Throw new Exception("Fail execute ($sql) ".db2_stmt_errormsg(),db2_stmt_error());
* ... and retrieve via try/catch + Exception methods.
*
* 'persistent' is one option
*
* @return bool
*/
public function connect($database, $user, $password, $options = null){

/*
Expand All @@ -20,8 +35,8 @@ public function connect($database, $user, $password, $options = null){
// Compensate for older ibm_db2 driver that may not do this check.
if ($user && empty($password)) {

$this->setErrorCode('08001');
$this->setErrorMsg('Authorization failure on distributed database connection attempt. SQLCODE=-30082');
$this->setErrorCode('08001');
$this->setErrorMsg('Authorization failure on distributed database connection attempt. SQLCODE=-30082');

return false;

Expand Down Expand Up @@ -50,34 +65,55 @@ public function connect($database, $user, $password, $options = null){
return false;

} //(public function connect($database, $user, $password, $options = null))


/**
* @param $conn
*/
public function disconnect( $conn ){

if(is_resource($conn))
db2_close($conn);

}

// disconnect, truly close, a persistent connection.
/**
* disconnect, truly close, a persistent connection.
*
* NOTE: Only available on i5/OS
*
* @param $conn
*/
public function disconnectPersistent( $conn ){

if(is_resource($conn))
db2_pclose($conn);

}



/**
* @return string
*/
public function getErrorCode(){

return $this->last_errorcode;
}

// added

/**
* @return string
*/
public function getErrorMsg(){

return $this->last_errormsg;
}


/**
* set error code and message based on last db2 prepare or execute error.
*
* @todo: consider using GET DIAGNOSTICS for even more message text:
* http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Frzala%2Frzalafinder.htm
*
* @param null $stmt
*/
protected function setStmtError($stmt = null) {
// set error code and message based on last db2 prepare or execute error.

Expand All @@ -94,18 +130,29 @@ protected function setStmtError($stmt = null) {
} //(if ($stmt))

} //(setStmtError($stmt = null))


/**
* @param $errorCode
*/
protected function setErrorCode($errorCode) {
$this->last_errorcode = $errorCode;
}



/**
* @param $errorMsg
*/
protected function setErrorMsg($errorMsg) {
$this->last_errormsg = $errorMsg;
}


/* this function used for special stored procedure call only */


/**
* this function used for special stored procedure call only
*
* @param $conn
* @param $sql
* @return bool
*/
public function execXMLStoredProcedure( $conn, $sql, $bindArray )
{

Expand Down Expand Up @@ -158,9 +205,19 @@ public function execXMLStoredProcedure( $conn, $sql, $bindArray )
return $outputXml;

} //(public function execXMLStoredProcedure)
/*returns a first column from sql stmt result set*/
// used in one place: iToolkitService's ReadSPLFData().
// TODO eliminate this method if possible.

/**
* returns a first column from sql stmt result set
*
* used in one place: iToolkitService's ReadSPLFData().
*
* @todo eliminate this method if possible.
*
* @param $conn
* @param $sql
* @throws \Exception
* @return array
*/
public function executeQuery($conn, $sql )
{

Expand Down
135 changes: 88 additions & 47 deletions ToolkitApi/Odbcsupp.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
<?php
<?php
/**
* Class odbcsupp
*
* @package ToolkitApi
*/
class odbcsupp {

private $last_errorcode = ''; // SQL State
private $last_errormsg = ''; // SQL Code with message

private $last_errorcode = ''; // SQL State
private $last_errormsg = ''; // SQL Code with message

// 'persistent' is one option
/**
*
* @todo should perhaps handle this method differently if $options are not passed
*
* @return bool|resource
*/
public function connect($database, $user, $password, $options = null){

$connectFunc = 'odbc_connect'; // default
Expand All @@ -27,55 +37,82 @@ public function connect($database, $user, $password, $options = null){
} //(if is resource)

} //(function connect)


/**
* @param $conn
*/
public function disconnect( $conn ){

if(is_resource($conn))
odbc_close($conn);

}

/**
* @return string
*/
public function getErrorCode(){

return $this->last_errorcode;
}

/**
* @return string
*/
public function getErrorMsg(){

return $this->last_errormsg;
}

/**
* set error code and message based on last odbc connection/prepare/execute error.
*
* @todo: consider using GET DIAGNOSTICS for even more message text:
* http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Frzala%2Frzalafinder.htm
*
* @param null $conn
*/
protected function setError($conn = null) {
// set error code and message based on last odbc connection/prepare/execute error.


public function getErrorCode(){

return $this->last_errorcode;
}

// added
public function getErrorMsg(){

return $this->last_errormsg;
}

protected function setError($conn = null) {
// set error code and message based on last odbc connection/prepare/execute error.

// TODO: consider using GET DIAGNOSTICS for even more message text:
// http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Frzala%2Frzalafinder.htm

if ($conn) {
// specific connection resource was provided
$this->setErrorCode(odbc_error($conn));
$this->setErrorMsg(odbc_errormsg($conn));
} else {
// no specific statemtent. Get last error
$this->setErrorCode(odbc_error());
$this->setErrorMsg(odbc_errormsg());
} //(if ($stmt))

} //(setStmtError($stmt = null))

protected function setErrorCode($errorCode) {
$this->last_errorcode = $errorCode;
}


protected function setErrorMsg($errorMsg) {
$this->last_errormsg = $errorMsg;
}
// TODO: consider using GET DIAGNOSTICS for even more message text:
// http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Frzala%2Frzalafinder.htm

if ($conn) {
// specific connection resource was provided
$this->setErrorCode(odbc_error($conn));
$this->setErrorMsg(odbc_errormsg($conn));
} else {
// no specific statemtent. Get last error
$this->setErrorCode(odbc_error());
$this->setErrorMsg(odbc_errormsg());
} //(if ($stmt))

/* this function used for special stored procedure call only */
} //(setStmtError($stmt = null))

/**
* @param $errorCode
*/
protected function setErrorCode($errorCode) {
$this->last_errorcode = $errorCode;
}

/**
* @param $errorMsg
*/
protected function setErrorMsg($errorMsg) {
$this->last_errormsg = $errorMsg;
}


/**
* this function used for special stored procedure call only
*
* @param $conn
* @param $stmt
* @param $bindArray
* @return string
*/
public function execXMLStoredProcedure( $conn, $stmt, $bindArray )
{

Expand Down Expand Up @@ -128,8 +165,12 @@ public function execXMLStoredProcedure( $conn, $stmt, $bindArray )
}//!$disconnect
return $outputXML;
}



/**
* @param $conn
* @param $stmt
* @return array
*/
public function executeQuery($conn, $stmt ){

$crsr = odbc_exec($conn, $stmt);
Expand Down
Loading

0 comments on commit 634a15d

Please sign in to comment.