git-svn-id: http://xe-core.googlecode.com/svn/trunk@970 201d5d3c-b55e-5fd7-737f-ddc643e51545

This commit is contained in:
zero 2007-04-05 04:22:21 +00:00
parent 49582a9e09
commit 736d569538
6 changed files with 103 additions and 67 deletions

View file

@ -153,7 +153,7 @@
* @brief 결과를 fetch * @brief 결과를 fetch
**/ **/
function _fetch($result) { function _fetch($result) {
if($this->errno!=0 || !$result) return; if($this->isError() || !$result) return;
while($tmp = mysql_fetch_object($result)) { while($tmp = mysql_fetch_object($result)) {
$output[] = $tmp; $output[] = $tmp;
} }
@ -384,7 +384,7 @@
} }
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) return; if($this->isError()) return;
$data = $this->_fetch($result); $data = $this->_fetch($result);
$buff = new Object(); $buff = new Object();
@ -421,7 +421,7 @@
$index = implode(',',$index_list); $index = implode(',',$index_list);
$query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count); $query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) { if($this->isError()) {
$buff = new Object(); $buff = new Object();
$buff->total_count = 0; $buff->total_count = 0;
$buff->total_page = 0; $buff->total_page = 0;

View file

@ -147,7 +147,7 @@
* @brief 결과를 fetch * @brief 결과를 fetch
**/ **/
function _fetch($result) { function _fetch($result) {
if($this->errno!=0 || !$result) return; if($this->isError() || !$result) return;
while($tmp = $result->fetch_object()) { while($tmp = $result->fetch_object()) {
$output[] = $tmp; $output[] = $tmp;
@ -379,7 +379,7 @@
} }
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) return; if($this->isError()) return;
$data = $this->_fetch($result); $data = $this->_fetch($result);
$buff = new Object(); $buff = new Object();
@ -416,7 +416,7 @@
$index = implode(',',$index_list); $index = implode(',',$index_list);
$query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count); $query = sprintf('select %s from %s %s order by %s limit %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) { if($this->isError()) {
$buff = new Object(); $buff = new Object();
$buff->total_count = 0; $buff->total_count = 0;
$buff->total_page = 0; $buff->total_page = 0;

View file

@ -149,7 +149,7 @@
* @brief 결과를 fetch * @brief 결과를 fetch
**/ **/
function _fetch($result) { function _fetch($result) {
if($this->errno!=0 || !$result) return; if($this->isError() || !$result) return;
while($tmp = sqlite_fetch_array($result, SQLITE_ASSOC)) { while($tmp = sqlite_fetch_array($result, SQLITE_ASSOC)) {
unset($obj); unset($obj);
@ -399,7 +399,7 @@
} }
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) return; if($this->isError()) return;
$data = $this->_fetch($result); $data = $this->_fetch($result);
$buff = new Object(); $buff = new Object();
@ -436,7 +436,7 @@
$index = implode(',',$index_list); $index = implode(',',$index_list);
$query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count); $query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
$result = $this->_query($query); $result = $this->_query($query);
if($this->errno!=0) { if($this->isError()) {
$buff = new Object(); $buff = new Object();
$buff->total_count = 0; $buff->total_count = 0;
$buff->total_page = 0; $buff->total_page = 0;

View file

@ -9,6 +9,9 @@
class DBSqlite3_pdo extends DB { class DBSqlite3_pdo extends DB {
var $handler = NULL; var $handler = NULL;
var $stmt = NULL;
var $bind_idx = 0;
var $database = NULL; ///< database var $database = NULL; ///< database
var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능) var $prefix = 'zb'; ///< 제로보드에서 사용할 테이블들의 prefix (한 DB에서 여러개의 제로보드 설치 가능)
@ -119,36 +122,46 @@
} }
/** /**
* @brief : 쿼리문의 실행 결과의 fetch 처리 * @brief : 쿼리문의 prepare
*
* query : query문 실행하고 result return\n
* fetch : reutrn 값이 없으면 NULL\n
* rows이면 array object\n
* row이면 object\n
* return\n
**/ **/
function _query($query) { function _prepare($query) {
if(!$this->isConnected()) return; if(!$this->isConnected()) return;
$this->query = $query; $this->query = $query;
$this->setError(0,'success'); $this->setError(0,'success');
try { $this->stmt = $this->handler->prepare($query);
$result = $this->handler->query($query); $this->bind_idx = 0;
return $result;
} catch (PDOException $e) {
$this->setError($e->getCode(), $e->getMessage());
return false;
}
} }
/** /**
* @brief 결과를 fetch * @brief : stmt에 binding params
**/ **/
function _fetch($result) { function _bind($val) {
if($this->errno!=0 || !$result) return; if(!$this->isConnected() || !$this->stmt) return;
foreach($result as $tmp) { $this->bind_idx ++;
$this->stmt->bindParam($this->bind_idx, $val);
}
/**
* @brief : prepare된 쿼리의 execute
**/
function _execute() {
if(!$this->isConnected() || !$this->stmt) return;
$this->bind_idx = 0;
$this->stmt->execute();
if($this->stmt->errorCode() != '00000') {
$this->setError($this->stmt->errorCode(),$this->stmt->errorInfo());
$this->stmt = null;
return false;
}
$output = null;
while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) {
unset($obj); unset($obj);
foreach($tmp as $key => $val) { foreach($tmp as $key => $val) {
$pos = strpos($key, '.'); $pos = strpos($key, '.');
@ -158,7 +171,9 @@
$output[] = $obj; $output[] = $obj;
} }
if(count($output)==1) return $output[0]; $this->stmt = null;
if(is_array($output) && count($output)==1) return $output[0];
return $output; return $output;
} }
@ -166,8 +181,9 @@
* @brief 1 증가되는 sequence값을 return * @brief 1 증가되는 sequence값을 return
**/ **/
function getNextSequence() { function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values ('')", $this->prefix); $query = sprintf("insert into %ssequence (seq) values ('0')", $this->prefix);
$this->handler->query($query); $this->_prepare($query);
$result = $this->_execute();
return $this->handler->lastInsertId(); return $this->handler->lastInsertId();
} }
@ -176,9 +192,8 @@
**/ **/
function isTableExists($target_name) { function isTableExists($target_name) {
$query = sprintf('pragma table_info(%s%s)', $this->prefix, $target_name); $query = sprintf('pragma table_info(%s%s)', $this->prefix, $target_name);
$stmt = $this->handler->prepare($query); $this->_prepare($query);
$result = $stmt->execute($query); if(!$this->_execute()) return false;
if(!$result) return false;
return true; return true;
} }
@ -232,20 +247,19 @@
$auto_increment = $column->attrs->auto_increment; $auto_increment = $column->attrs->auto_increment;
if($auto_increment) { if($auto_increment) {
$column_schema[] = sprintf('%s %s %s', $column_schema[] = sprintf('%s %s PRIMARY KEY %s',
$name, $name,
$this->column_type[$type], $this->column_type[$type],
$auto_increment?'AUTOINCREMENT':'' $auto_increment?'AUTOINCREMENT':''
); );
} else { } else {
$column_schema[] = sprintf('%s %s%s %s %s %s %s', $column_schema[] = sprintf('%s %s%s %s %s %s',
$name, $name,
$this->column_type[$type], $this->column_type[$type],
$size?'('.$size.')':'', $size?'('.$size.')':'',
$notnull?'NOT NULL':'', $notnull?'NOT NULL':'',
$primary_key?'PRIMARY KEY':'', $primary_key?'PRIMARY KEY':'',
$default?"DEFAULT '".$default."'":'', $default?"DEFAULT '".$default."'":''
$auto_increment?'AUTOINCREMENT':''
); );
} }
@ -253,26 +267,41 @@
else if($index) $index_list[$index][] = $name; else if($index) $index_list[$index][] = $name;
} }
$this->begin();
$schema = sprintf('CREATE TABLE %s (%s%s) ;', $table_name," ", implode($column_schema,", ")); $schema = sprintf('CREATE TABLE %s (%s%s) ;', $table_name," ", implode($column_schema,", "));
$output = $this->_query($schema); $this->_prepare($schema);
if(!$output) return false; $this->_execute();
if($this->isError()) {
$this->rollback();
return;
}
if(count($unique_list)) { if(count($unique_list)) {
foreach($unique_list as $key => $val) { foreach($unique_list as $key => $val) {
$query = sprintf('CREATE UNIQUE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); $query = sprintf('CREATE UNIQUE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema); $this->_prepare($query);
if(!$output) return false; $this->_execute();
if($this->isError()) {
$this->rollback();
return;
}
} }
} }
if(count($unique_list)) { if(count($unique_list)) {
foreach($unique_list as $key => $val) { foreach($unique_list as $key => $val) {
$query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val)); $query = sprintf('CREATE INDEX IF NOT EXISTS %s (%s)', $key, implode(',',$val));
$output = $this->_query($schema); $this->_prepare($query);
if(!$output) return false; $this->_execute();
if($this->isError()) {
$this->rollback();
return;
}
} }
} }
$this->commit();
} }
/** /**
@ -280,7 +309,8 @@
**/ **/
function dropTable($target_name) { function dropTable($target_name) {
$query = sprintf('DROP TABLE %s%s;', $this->prefix, $this->addQuotes($target_name)); $query = sprintf('DROP TABLE %s%s;', $this->prefix, $this->addQuotes($target_name));
$this->_query($query); $this->_prepare($query);
$this->_execute();
} }
/** /**
@ -288,7 +318,8 @@
**/ **/
function renameTable($source_name, $targe_name) { function renameTable($source_name, $targe_name) {
$query = sprintf("ALTER TABLE %s%s RENAME TO %s%s;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name)); $query = sprintf("ALTER TABLE %s%s RENAME TO %s%s;", $this->prefix, $this->addQuotes($source_name), $this->prefix, $this->addQuotes($targe_name));
$this->_query($query); $this->_prepare($query);
$this->_execute();
} }
/** /**
@ -296,7 +327,8 @@
**/ **/
function truncateTable($target_name) { function truncateTable($target_name) {
$query = sprintf("VACUUM %s%s;", $this->prefix, $this->addQuotes($target_name)); $query = sprintf("VACUUM %s%s;", $this->prefix, $this->addQuotes($target_name));
$this->_query($query); $this->_prepare($query);
$this->_execute();
} }
/** /**
@ -320,11 +352,14 @@
} }
$query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',',$prepare_list)); $query = sprintf("INSERT INTO %s%s (%s) VALUES (%s);", $this->prefix, $table, implode(',',$key_list), implode(',',$prepare_list));
$stmt = $this->handler->prepare($query);
$this->_prepare($query);
$val_count = count($val_list); $val_count = count($val_list);
for($i=0;$i<$val_count;$i++) $stmt->bindParam($i+1, $val_list[$i]); for($i=0;$i<$val_count;$i++) $this->_bind($val_list[$i]);
return $stmt->execute();
$this->_execute();
return $this->isError();
} }
/** /**
@ -346,11 +381,13 @@
if($condition) $condition = ' WHERE '.$condition; if($condition) $condition = ' WHERE '.$condition;
$query = sprintf("UPDATE %s%s SET %s %s;", $this->prefix, $table, $update_query, $condition); $query = sprintf("UPDATE %s%s SET %s %s;", $this->prefix, $table, $update_query, $condition);
$stmt = $this->handler->prepare($query); $this->_prepare($query);
$val_count = count($val_list); $val_count = count($val_list);
for($i=0;$i<$val_count;$i++) $stmt->bindParam($i+1, $val_list[$i]); for($i=0;$i<$val_count;$i++) $this->_bind($val_list[$i]);
return $stmt->execute();
$this->_execute();
return $this->isError();
} }
/** /**
@ -362,7 +399,10 @@
if($condition) $condition = ' WHERE '.$condition; if($condition) $condition = ' WHERE '.$condition;
$query = sprintf("DELETE FROM %s%s %s;", $this->prefix, $table, $condition); $query = sprintf("DELETE FROM %s%s %s;", $this->prefix, $table, $condition);
return $this->_query($query); $this->_prepare($query);
$this->_execute();
return $this->isError();
} }
/** /**
@ -401,9 +441,9 @@
if(count($index_list)) $query .= ' ORDER BY '.implode(',',$index_list); if(count($index_list)) $query .= ' ORDER BY '.implode(',',$index_list);
} }
$result = $this->_query($query); $this->_prepare($query);
if($this->errno!=0) return; $data = $this->_execute();
$data = $this->_fetch($result); if($this->isError()) return;
$buff = new Object(); $buff = new Object();
$buff->data = $data; $buff->data = $data;
@ -420,8 +460,8 @@
// 전체 개수를 구함 // 전체 개수를 구함
$count_query = sprintf("select count(*) as count from %s %s", $table, $condition); $count_query = sprintf("select count(*) as count from %s %s", $table, $condition);
$result = $this->_query($count_query); $this->_prepare($count_query);
$count_output = $this->_fetch($result); $count_output = $this->_execute();
$total_count = (int)$count_output->count; $total_count = (int)$count_output->count;
// 전체 페이지를 구함 // 전체 페이지를 구함
@ -438,20 +478,19 @@
$index = implode(',',$index_list); $index = implode(',',$index_list);
$query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count); $query = sprintf('SELECT %s FROM %s %s ORDER BY %s LIMIT %d, %d', $columns, $table, $condition, $index, $start_count, $navigation->list_count);
$result = $this->_query($query); $this->_prepare($query);
if($this->errno!=0) { $tmp_data = $this->_execute();
if($this->isError()) {
$buff = new Object(); $buff = new Object();
$buff->total_count = 0; $buff->total_count = 0;
$buff->total_page = 0; $buff->total_page = 0;
$buff->page = 1; $buff->page = 1;
$buff->data = array(); $buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count); $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $navigation->page_count);
return $buff; return $buff;
} }
$virtual_no = $total_count - ($page-1)*$navigation->list_count; $virtual_no = $total_count - ($page-1)*$navigation->list_count;
$tmp_data = $this->_fetch($result);
if($tmp_data) { if($tmp_data) {
if(!is_array($tmp_data)) $tmp_data = array($tmp_data); if(!is_array($tmp_data)) $tmp_data = array($tmp_data);
foreach($tmp_data as $tmp) { foreach($tmp_data as $tmp) {

View file

@ -1,5 +1,4 @@
<?php <?php
ob_start();
/** /**
* @file index.php * @file index.php
* @author zero (zero@zeroboard.com) * @author zero (zero@zeroboard.com)
@ -48,6 +47,4 @@ ob_start();
$oModuleHandler->init(); $oModuleHandler->init();
$oModule = &$oModuleHandler->procModule(); $oModule = &$oModuleHandler->procModule();
$oModuleHandler->displayContent($oModule); $oModuleHandler->displayContent($oModule);
debugPrint(ob_get_contents());
ob_end_flush();
?> ?>

View file

@ -131,7 +131,7 @@
</tr> </tr>
<tr> <tr>
<th rowspan="2">{$lang->admin_id}</th> <th rowspan="2">{$lang->admin_id}</th>
<td><textarea name="admin_id">{implode(",",$module_info->admin_id)}</textarea></td> <td><textarea name="admin_id"><!--@if($module_info->admin_id)-->{implode(",",$module_info->admin_id)}<!--@end--></textarea></td>
</tr> </tr>
<tr> <tr>
<td>{$lang->about_admin_id}</td> <td>{$lang->about_admin_id}</td>