mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-27 22:33:10 +09:00
english comments added
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0_english@8278 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
693e215bc1
commit
4d272994dd
219 changed files with 6407 additions and 8705 deletions
|
|
@ -2,34 +2,34 @@
|
|||
/**
|
||||
* @class DBPostgreSQL
|
||||
* @author ioseph (ioseph@postgresql.kr) updated by yoonjong.joh@gmail.com
|
||||
* @brief MySQL DBMS를 이용하기 위한 class
|
||||
* @brief Class to use PostgreSQL DBMS
|
||||
* @version 0.2
|
||||
*
|
||||
* postgresql handling class
|
||||
* 2009.02.10 update 와 delete query를 실행할때 table 이름에 alias 사용하는 것을 없앰. 지원 안함
|
||||
* order by clause를 실행할때 함수를 실행 하는 부분을 column alias로 대체.
|
||||
* 2009.02.11 dropColumn() function이 추가
|
||||
* 2009.02.13 addColumn() 함수 변경
|
||||
* 2009.02.10 update and delete query for the table name at runtime, eliminating the alias to use. Not Supported
|
||||
* when running order by clause column alias to run a function to replace parts.
|
||||
* 2009.02.11 dropColumn() function added
|
||||
* 2009.02.13 addColumn() function changes
|
||||
**/
|
||||
|
||||
class DBPostgresql extends DB
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief PostgreSQL DB에 접속하기 위한 정보
|
||||
* @brief Connection information for PostgreSQL DB
|
||||
**/
|
||||
var $hostname = '127.0.0.1'; ///< hostname
|
||||
var $userid = null; ///< user id
|
||||
var $password = null; ///< password
|
||||
var $database = null; ///< database
|
||||
var $prefix = 'xe'; ///< XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE설치 가능)
|
||||
var $prefix = 'xe'; // / <prefix of a tablename (One or more XEs can be installed in a single DB)
|
||||
var $comment_syntax = '/* %s */';
|
||||
|
||||
/**
|
||||
* @brief postgresql에서 사용될 column type
|
||||
* @brief column type used in postgresql
|
||||
*
|
||||
* column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에
|
||||
* 각 DBMS에 맞게 replace 해주어야 한다
|
||||
* Becasue a common column type in schema/query xml is used for colum_type,
|
||||
* it should be replaced properly for each DBMS
|
||||
**/
|
||||
var $column_type = array(
|
||||
'bignumber' => 'bigint',
|
||||
|
|
@ -60,7 +60,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 설치 가능 여부를 return
|
||||
* @brief Return if it is installable
|
||||
**/
|
||||
function isSupported()
|
||||
{
|
||||
|
|
@ -70,7 +70,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief DB정보 설정 및 connect/ close
|
||||
* @brief DB settings and connect/close
|
||||
**/
|
||||
function _setDBInfo()
|
||||
{
|
||||
|
|
@ -86,40 +86,36 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief DB 접속
|
||||
* @brief DB Connection
|
||||
**/
|
||||
function _connect()
|
||||
{
|
||||
// pg용 connection string
|
||||
// the connection string for PG
|
||||
$conn_string = "";
|
||||
|
||||
// db 정보가 없으면 무시
|
||||
// Ignore if no DB information exists
|
||||
if (!$this->hostname || !$this->userid || !$this->database)
|
||||
return;
|
||||
|
||||
// connection string 만들기
|
||||
// Create connection string
|
||||
$conn_string .= ($this->hostname) ? " host=$this->hostname" : "";
|
||||
$conn_string .= ($this->userid) ? " user=$this->userid" : "";
|
||||
$conn_string .= ($this->password) ? " password=$this->password" : "";
|
||||
$conn_string .= ($this->database) ? " dbname=$this->database" : "";
|
||||
$conn_string .= ($this->port) ? " port=$this->port" : "";
|
||||
|
||||
// 접속시도
|
||||
// Attempt to connect
|
||||
$this->fd = @pg_connect($conn_string);
|
||||
if (!$this->fd || pg_connection_status($this->fd) != PGSQL_CONNECTION_OK) {
|
||||
$this->setError(-1, "CONNECTION FAILURE");
|
||||
return;
|
||||
}
|
||||
|
||||
// 접속체크
|
||||
// Check connections
|
||||
$this->is_connected = true;
|
||||
$this->password = md5($this->password);
|
||||
// utf8임을 지정
|
||||
// Set utf8
|
||||
//$this ->_query('set client_encoding to uhc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DB접속 해제
|
||||
* @brief DB disconnection
|
||||
**/
|
||||
function close()
|
||||
{
|
||||
|
|
@ -129,7 +125,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 쿼리에서 입력되는 문자열 변수들의 quotation 조절
|
||||
* @brief Add quotes on the string variables in a query
|
||||
**/
|
||||
function addQuotes($string)
|
||||
{
|
||||
|
|
@ -141,7 +137,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 트랜잭션 시작
|
||||
* @brief Begin transaction
|
||||
**/
|
||||
function begin()
|
||||
{
|
||||
|
|
@ -152,7 +148,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 롤백
|
||||
* @brief Rollback
|
||||
**/
|
||||
function rollback()
|
||||
{
|
||||
|
|
@ -163,7 +159,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 커밋
|
||||
* @brief Commits
|
||||
**/
|
||||
function commit()
|
||||
{
|
||||
|
|
@ -174,12 +170,12 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief : 쿼리문의 실행 및 결과의 fetch 처리
|
||||
* @brief : Run a query and fetch the result
|
||||
*
|
||||
* query : query문 실행하고 result return\n
|
||||
* fetch : reutrn 된 값이 없으면 NULL\n
|
||||
* rows이면 array object\n
|
||||
* row이면 object\n
|
||||
* query: run a query and return the result \n
|
||||
* fetch: NULL if no value is returned \n
|
||||
* array object if rows are returned \n
|
||||
* object if a row is returned \n
|
||||
* return\n
|
||||
**/
|
||||
function _query($query)
|
||||
|
|
@ -208,16 +204,12 @@ class DBPostgresql extends DB
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// 쿼리 시작을 알림
|
||||
// Notify to start a query execution
|
||||
$this->actStart($query);
|
||||
$arr = array('Hello', 'World!', 'Beautiful', 'Day!');
|
||||
|
||||
|
||||
// 쿼리 문 실행
|
||||
// Run the query statement
|
||||
$result = @pg_query($this->fd, $query);
|
||||
|
||||
// 오류 체크
|
||||
// Error Check
|
||||
if (!$result) {
|
||||
// var_dump($l_query_array);
|
||||
//var_dump($query);
|
||||
|
|
@ -225,16 +217,14 @@ class DBPostgresql extends DB
|
|||
//var_dump(debug_backtrace());
|
||||
$this->setError(1, pg_last_error($this->fd));
|
||||
}
|
||||
|
||||
// 쿼리 실행 종료를 알림
|
||||
// Notify to complete a query execution
|
||||
$this->actFinish();
|
||||
|
||||
// 결과 리턴
|
||||
// Return result
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 결과를 fetch
|
||||
* @brief Fetch results
|
||||
**/
|
||||
function _fetch($result)
|
||||
{
|
||||
|
|
@ -249,7 +239,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 1씩 증가되는 sequence값을 return (postgresql의 auto_increment는 sequence테이블에서만 사용)
|
||||
* @brief Return sequence value incremented by 1(in postgresql, auto_increment is used in the sequence table only)
|
||||
**/
|
||||
function getNextSequence()
|
||||
{
|
||||
|
|
@ -260,7 +250,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 테이블 기생성 여부 return
|
||||
* @brief Return if a table already exists
|
||||
**/
|
||||
function isTableExists($target_name)
|
||||
{
|
||||
|
|
@ -277,7 +267,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블에 특정 column 추가
|
||||
* @brief Add a column to a table
|
||||
**/
|
||||
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default =
|
||||
NULL, $notnull = false)
|
||||
|
|
@ -309,7 +299,7 @@ class DBPostgresql extends DB
|
|||
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블의 column의 정보를 return
|
||||
* @brief Return column information of a table
|
||||
**/
|
||||
function isColumnExists($table_name, $column_name)
|
||||
{
|
||||
|
|
@ -329,7 +319,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블에 특정 인덱스 추가
|
||||
* @brief Add an index to a table
|
||||
* $target_columns = array(col1, col2)
|
||||
* $is_unique? unique : none
|
||||
**/
|
||||
|
|
@ -340,8 +330,7 @@ class DBPostgresql extends DB
|
|||
|
||||
if (strpos($table_name, $this->prefix) === false)
|
||||
$table_name = $this->prefix . $table_name;
|
||||
|
||||
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
|
||||
// Use a tablename before an index name to avoid defining the same index
|
||||
$index_name = $table_name . $index_name;
|
||||
|
||||
$query = sprintf("create %s index %s on %s (%s);", $is_unique ? 'unique' : '', $index_name,
|
||||
|
|
@ -350,7 +339,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블에 특정 column 제거
|
||||
* @brief Delete a column from a table
|
||||
**/
|
||||
function dropColumn($table_name, $column_name)
|
||||
{
|
||||
|
|
@ -359,14 +348,13 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블의 특정 인덱스 삭제
|
||||
* @brief Drop an index from a table
|
||||
**/
|
||||
function dropIndex($table_name, $index_name, $is_unique = false)
|
||||
{
|
||||
if (strpos($table_name, $this->prefix) === false)
|
||||
$table_name = $this->prefix . $table_name;
|
||||
|
||||
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
|
||||
// Use a tablename before an index name to avoid defining the same index
|
||||
$index_name = $table_name . $index_name;
|
||||
|
||||
$query = sprintf("drop index %s", $index_name);
|
||||
|
|
@ -375,14 +363,13 @@ class DBPostgresql extends DB
|
|||
|
||||
|
||||
/**
|
||||
* @brief 특정 테이블의 index 정보를 return
|
||||
* @brief Return index information of a table
|
||||
**/
|
||||
function isIndexExists($table_name, $index_name)
|
||||
{
|
||||
if (strpos($table_name, $this->prefix) === false)
|
||||
$table_name = $this->prefix . $table_name;
|
||||
|
||||
// index_name의 경우 앞에 table이름을 붙여줘서 중복을 피함
|
||||
// Use a tablename before an index name to avoid defining the same index
|
||||
$index_name = $table_name . $index_name;
|
||||
|
||||
//$query = sprintf("show indexes from %s%s where key_name = '%s' ", $this->prefix, $table_name, $index_name);
|
||||
|
|
@ -402,7 +389,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief xml 을 받아서 테이블을 생성
|
||||
* @brief Create a table by using xml file
|
||||
**/
|
||||
function createTableByXml($xml_doc)
|
||||
{
|
||||
|
|
@ -410,19 +397,19 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief xml 을 받아서 테이블을 생성
|
||||
* @brief Create a table by using xml file
|
||||
**/
|
||||
function createTableByXmlFile($file_name)
|
||||
{
|
||||
if (!file_exists($file_name))
|
||||
return;
|
||||
// xml 파일을 읽음
|
||||
// read xml file
|
||||
$buff = FileHandler::readFile($file_name);
|
||||
return $this->_createTable($buff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief schema xml을 이용하여 create table query생성
|
||||
* @brief generate a query statement to create a table by using schema xml
|
||||
*
|
||||
* type : number, varchar, text, char, date, \n
|
||||
* opt : notnull, default, size\n
|
||||
|
|
@ -433,8 +420,7 @@ class DBPostgresql extends DB
|
|||
// xml parsing
|
||||
$oXml = new XmlParser();
|
||||
$xml_obj = $oXml->parse($xml_doc);
|
||||
|
||||
// 테이블 생성 schema 작성
|
||||
// Create a table schema
|
||||
$table_name = $xml_obj->table->attrs->name;
|
||||
|
||||
if ($table_name == 'sequence') {
|
||||
|
|
@ -508,7 +494,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 조건문 작성하여 return
|
||||
* @brief Return conditional clause
|
||||
**/
|
||||
function getCondition($output)
|
||||
{
|
||||
|
|
@ -564,16 +550,15 @@ class DBPostgresql extends DB
|
|||
|
||||
|
||||
/**
|
||||
* @brief insertAct 처리
|
||||
* @brief Handle the insertAct
|
||||
**/
|
||||
function _executeInsertAct($output)
|
||||
{
|
||||
// 테이블 정리
|
||||
// List tables
|
||||
foreach ($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix . $val;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
// List columns
|
||||
foreach ($output->columns as $key => $val) {
|
||||
$name = $val['name'];
|
||||
$value = $val['value'];
|
||||
|
|
@ -594,17 +579,16 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief updateAct 처리
|
||||
* @brief Handle updateAct
|
||||
**/
|
||||
function _executeUpdateAct($output)
|
||||
{
|
||||
// 테이블 정리
|
||||
// List tables
|
||||
foreach ($output->tables as $key => $val) {
|
||||
//$table_list[] = $this->prefix.$val.' as '.$key;
|
||||
$table_list[] = $this->prefix . $val;
|
||||
}
|
||||
|
||||
// 컬럼 정리
|
||||
// List columns
|
||||
foreach ($output->columns as $key => $val) {
|
||||
if (!isset($val['value']))
|
||||
continue;
|
||||
|
|
@ -621,8 +605,7 @@ class DBPostgresql extends DB
|
|||
$column_list[] = sprintf("%s = %s", $name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
// List the conditional clause
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("update %s set %s %s", implode(',', $table_list), implode(',',
|
||||
|
|
@ -632,16 +615,15 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief deleteAct 처리
|
||||
* @brief Handle deleteAct
|
||||
**/
|
||||
function _executeDeleteAct($output)
|
||||
{
|
||||
// 테이블 정리
|
||||
// List tables
|
||||
foreach ($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix . $val;
|
||||
}
|
||||
|
||||
// 조건절 정리
|
||||
// List the conditional clause
|
||||
$condition = $this->getCondition($output);
|
||||
|
||||
$query = sprintf("delete from %s %s", implode(',', $table_list), $condition);
|
||||
|
|
@ -650,14 +632,14 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief selectAct 처리
|
||||
* @brief Handle selectAct
|
||||
*
|
||||
* select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해\n
|
||||
* navigation이라는 method를 제공
|
||||
* In order to get a list of pages easily when selecting \n
|
||||
* it supports a method as navigation
|
||||
**/
|
||||
function _executeSelectAct($output)
|
||||
{
|
||||
// 테이블 정리
|
||||
// List tables
|
||||
$table_list = array();
|
||||
foreach ($output->tables as $key => $val) {
|
||||
$table_list[] = $this->prefix . $val . ' as ' . $key;
|
||||
|
|
@ -709,8 +691,7 @@ class DBPostgresql extends DB
|
|||
if ($output->list_count && $output->page)
|
||||
return $this->_getNavigationData($table_list, $columns, $left_join, $condition,
|
||||
$output);
|
||||
|
||||
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
|
||||
// Add a condition to use an index when sorting in order by list_order, update_order
|
||||
if ($output->order) {
|
||||
$conditions = $this->getConditionList($output);
|
||||
if (!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
|
||||
|
|
@ -794,9 +775,9 @@ class DBPostgresql extends DB
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
|
||||
* @brief Paging is handled if navigation information exists in the query xml
|
||||
*
|
||||
* 그닥 좋지는 않은 구조이지만 편리하다.. -_-;
|
||||
* It is quite convenient although its structure is not good at all .. -_-;
|
||||
**/
|
||||
function _getNavigationData($table_list, $columns, $left_join, $condition, $output)
|
||||
{
|
||||
|
|
@ -804,8 +785,8 @@ class DBPostgresql extends DB
|
|||
|
||||
$column_list = $output->column_list;
|
||||
/*
|
||||
// group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정
|
||||
// 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다.
|
||||
// Modified to find total number of SELECT queries having group by clause
|
||||
// If it works correctly, uncomment the following codes
|
||||
//
|
||||
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
|
||||
$total_count = $this->getCountCache($output->tables, $count_condition);
|
||||
|
|
@ -820,7 +801,7 @@ class DBPostgresql extends DB
|
|||
}
|
||||
*/
|
||||
|
||||
// 전체 개수를 구함
|
||||
// Get a total count
|
||||
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',', $table_list), implode(' ', $left_join), $condition);
|
||||
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
|
||||
$result = $this->_query($count_query);
|
||||
|
|
@ -835,15 +816,14 @@ class DBPostgresql extends DB
|
|||
if (!$page)
|
||||
$page = 1;
|
||||
|
||||
// 전체 페이지를 구함
|
||||
// Get a total page
|
||||
if ($total_count) $total_page = (int)(($total_count - 1) / $list_count) + 1;
|
||||
else $total_page = 1;
|
||||
|
||||
// 페이지 변수를 체크
|
||||
// Check Page variables
|
||||
if ($page > $total_page) $page = $total_page;
|
||||
$start_count = ($page - 1) * $list_count;
|
||||
|
||||
// list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가
|
||||
// Add a condition to use an index when sorting in order by list_order, update_order
|
||||
if ($output->order) {
|
||||
$conditions = $this->getConditionList($output);
|
||||
if (!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue