SQLite3를 PDO로 이용하여 class. 더 자세히 ...


Public 멤버 함수 | |
| DBSqlite3_pdo () | |
| constructor | |
| isSupported () | |
| 설치 가능 여부를 return | |
| _setDBInfo () | |
| DB정보 설정 및 connect/ close. | |
| _connect () | |
| DB 접속. | |
| close () | |
| DB접속 해제. | |
| begin () | |
| 트랜잭션 시작 | |
| rollback () | |
| 롤백 | |
| commit ($force=false) | |
| 커밋 | |
| addQuotes ($string) | |
| 쿼리에서 입력되는 문자열 변수들의 quotation 조절 | |
| _prepare ($query) | |
| : 쿼리문의 prepare | |
| _bind ($val) | |
| : stmt에 binding params | |
| _execute () | |
| : prepare된 쿼리의 execute | |
| getNextSequence () | |
| 1씩 증가되는 sequence값을 return | |
| isTableExists ($target_name) | |
| 테이블 기생성 여부 return | |
| addColumn ($table_name, $column_name, $type='number', $size='', $default= '', $notnull=false) | |
| 특정 테이블에 특정 column 추가 | |
| dropColumn ($table_name, $column_name) | |
| 특정 테이블에 특정 column 제거 | |
| isColumnExists ($table_name, $column_name) | |
| 특정 테이블의 column의 정보를 return | |
| addIndex ($table_name, $index_name, $target_columns, $is_unique=false) | |
| 특정 테이블에 특정 인덱스 추가 $target_columns = array(col1, col2) $is_unique? unique : none | |
| dropIndex ($table_name, $index_name, $is_unique=false) | |
| 특정 테이블의 특정 인덱스 삭제 | |
| isIndexExists ($table_name, $index_name) | |
| 특정 테이블의 index 정보를 return | |
| createTableByXml ($xml_doc) | |
| xml 을 받아서 테이블을 생성 | |
| createTableByXmlFile ($file_name) | |
| xml 을 받아서 테이블을 생성 | |
| _createTable ($xml_doc) | |
| schema xml을 이용하여 create table query생성 | |
| getCondition ($output) | |
| 조건문 작성하여 return | |
| getLeftCondition ($conditions, $column_type) | |
| _getCondition ($conditions, $column_type) | |
| _executeInsertAct ($output) | |
| insertAct 처리 | |
| _executeUpdateAct ($output) | |
| updateAct 처리 | |
| _executeDeleteAct ($output) | |
| deleteAct 처리 | |
| _executeSelectAct ($output) | |
| selectAct 처리 | |
| _getNavigationData ($table_list, $columns, $left_join, $condition, $output) | |
| query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다 | |
Public 속성 | |
| $database = NULL | |
| database | |
| $prefix = 'xe' | |
| XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능). | |
| $handler = NULL | |
| $stmt = NULL | |
| $bind_idx = 0 | |
| $bind_vars = array() | |
| $column_type | |
| sqlite3 에서 사용될 column type | |
SQLite3를 PDO로 이용하여 class.
DBSqlite3_pdo.class.php 파일의 9 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::_bind | ( | $ | val | ) |
: stmt에 binding params
DBSqlite3_pdo.class.php 파일의 154 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::isConnected().
00154 { 00155 if(!$this->isConnected() || !$this->stmt) return; 00156 00157 $this->bind_idx ++; 00158 $this->bind_vars[] = $val; 00159 $this->stmt->bindParam($this->bind_idx, $val); 00160 }

| DBSqlite3_pdo::_connect | ( | ) |
DB 접속.
DBSqlite3_pdo.class.php 파일의 71 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::setError().
다음에 의해서 참조됨 : DBSqlite3_pdo().
00071 { 00072 // db 정보가 없으면 무시 00073 if(!$this->database) return; 00074 00075 // 데이터 베이스 파일 접속 시도 00076 $this->handler = new PDO('sqlite:'.$this->database); 00077 00078 if(!file_exists($this->database) || $error) { 00079 $this->setError(-1,'permission denied to access database'); 00080 //$this->setError(-1,$error); 00081 $this->is_connected = false; 00082 return; 00083 } 00084 00085 // 접속체크 00086 $this->is_connected = true; 00087 }

| DBSqlite3_pdo::_createTable | ( | $ | xml_doc | ) |
schema xml을 이용하여 create table query생성
type : number, varchar, text, char, date,
opt : notnull, default, size
index : primary key, index, unique
DBSqlite3_pdo.class.php 파일의 323 번째 라인에서 정의되었습니다.
00323 { 00324 // xml parsing 00325 $oXml = new XmlParser(); 00326 $xml_obj = $oXml->parse($xml_doc); 00327 00328 // 테이블 생성 schema 작성 00329 $table_name = $xml_obj->table->attrs->name; 00330 if($this->isTableExists($table_name)) return; 00331 $table_name = $this->prefix.$table_name; 00332 00333 if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column; 00334 else $columns = $xml_obj->table->column; 00335 00336 foreach($columns as $column) { 00337 $name = $column->attrs->name; 00338 $type = $column->attrs->type; 00339 if(strtoupper($this->column_type[$type])=='INTEGER') $size = ''; 00340 else $size = $column->attrs->size; 00341 $notnull = $column->attrs->notnull; 00342 $primary_key = $column->attrs->primary_key; 00343 $index = $column->attrs->index; 00344 $unique = $column->attrs->unique; 00345 $default = $column->attrs->default; 00346 $auto_increment = $column->attrs->auto_increment; 00347 00348 if($auto_increment) { 00349 $column_schema[] = sprintf('%s %s PRIMARY KEY %s', 00350 $name, 00351 $this->column_type[$type], 00352 $auto_increment?'AUTOINCREMENT':'' 00353 ); 00354 } else { 00355 $column_schema[] = sprintf('%s %s%s %s %s %s', 00356 $name, 00357 $this->column_type[$type], 00358 $size?'('.$size.')':'', 00359 $notnull?'NOT NULL':'', 00360 $primary_key?'PRIMARY KEY':'', 00361 $default?"DEFAULT '".$default."'":'' 00362 ); 00363 } 00364 00365 if($unique) $unique_list[$unique][] = $name; 00366 else if($index) $index_list[$index][] = $name; 00367 } 00368 00369 $schema = sprintf('CREATE TABLE %s (%s%s) ;', $table_name," ", implode($column_schema,", ")); 00370 $this->_prepare($schema); 00371 $this->_execute(); 00372 if($this->isError()) return; 00373 00374 if(count($unique_list)) { 00375 foreach($unique_list as $key => $val) { 00376 $query = sprintf('CREATE UNIQUE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val)); 00377 $this->_prepare($query); 00378 $this->_execute(); 00379 if($this->isError()) $this->rollback(); 00380 } 00381 } 00382 00383 if(count($index_list)) { 00384 foreach($index_list as $key => $val) { 00385 $query = sprintf('CREATE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val)); 00386 $this->_prepare($query); 00387 $this->_execute(); 00388 if($this->isError()) $this->rollback(); 00389 } 00390 } 00391 }
| DBSqlite3_pdo::_execute | ( | ) |
: prepare된 쿼리의 execute
DBSqlite3_pdo.class.php 파일의 165 번째 라인에서 정의되었습니다.
다음을 참조함 : $output, DB::isConnected(), null.
00165 { 00166 if(!$this->isConnected() || !$this->stmt) return; 00167 00168 $this->stmt->execute(); 00169 00170 if($this->stmt->errorCode() === '00000') { 00171 $output = null; 00172 while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) { 00173 unset($obj); 00174 foreach($tmp as $key => $val) { 00175 $pos = strpos($key, '.'); 00176 if($pos) $key = substr($key, $pos+1); 00177 $obj->{$key} = str_replace("''","'",$val); 00178 } 00179 $output[] = $obj; 00180 } 00181 } else { 00182 $this->setError($this->stmt->errorCode(),print_r($this->stmt->errorInfo(),true)); 00183 } 00184 00185 $this->stmt = null; 00186 $this->actFinish(); 00187 00188 if(is_array($output) && count($output)==1) return $output[0]; 00189 return $output; 00190 }

| DBSqlite3_pdo::_executeDeleteAct | ( | $ | output | ) |
deleteAct 처리
DBSqlite3_pdo.class.php 파일의 542 번째 라인에서 정의되었습니다.
다음을 참조함 : $output.
00542 { 00543 // 테이블 정리 00544 foreach($output->tables as $key => $val) { 00545 $table_list[] = $this->prefix.$val; 00546 } 00547 00548 // 조건절 정리 00549 $condition = $this->getCondition($output); 00550 00551 $query = sprintf("delete from %s %s", implode(',',$table_list), $condition); 00552 00553 $this->_prepare($query); 00554 return $this->_execute(); 00555 }
| DBSqlite3_pdo::_executeInsertAct | ( | $ | output | ) |
insertAct 처리
DBSqlite3_pdo.class.php 파일의 440 번째 라인에서 정의되었습니다.
다음을 참조함 : $output.
00440 { 00441 // 테이블 정리 00442 foreach($output->tables as $key => $val) { 00443 $table_list[] = $this->prefix.$val; 00444 } 00445 00446 // 컬럼 정리 00447 foreach($output->columns as $key => $val) { 00448 $name = $val['name']; 00449 $value = $val['value']; 00450 00451 $key_list[] = $name; 00452 00453 if($output->column_type[$name]!='number') $val_list[] = $this->addQuotes($value); 00454 else { 00455 if(!$value || is_numeric($value)) $value = (int)$value; 00456 $val_list[] = $value; 00457 } 00458 00459 $prepare_list[] = '?'; 00460 } 00461 00462 $query = sprintf("INSERT INTO %s (%s) VALUES (%s);", implode(',',$table_list), implode(',',$key_list), implode(',',$prepare_list)); 00463 00464 $this->_prepare($query); 00465 00466 $val_count = count($val_list); 00467 for($i=0;$i<$val_count;$i++) $this->_bind($val_list[$i]); 00468 00469 return $this->_execute(); 00470 }
| DBSqlite3_pdo::_executeSelectAct | ( | $ | output | ) |
selectAct 처리
select의 경우 특정 페이지의 목록을 가져오는 것을 편하게 하기 위해
navigation이라는 method를 제공
DBSqlite3_pdo.class.php 파일의 563 번째 라인에서 정의되었습니다.
00563 { 00564 // 테이블 정리 00565 $table_list = array(); 00566 foreach($output->tables as $key => $val) { 00567 $table_list[] = $this->prefix.$val.' as '.$key; 00568 } 00569 00570 $left_join = array(); 00571 // why??? 00572 $left_tables= (array)$output->left_tables; 00573 00574 foreach($left_tables as $key => $val) { 00575 $condition = $this->_getCondition($output->left_conditions[$key],$output->column_type); 00576 if($condition){ 00577 $left_join[] = $val . ' '.$this->prefix.$output->_tables[$key].' as '.$key . ' on (' . $condition . ')'; 00578 } 00579 } 00580 00581 00582 00583 if(!$output->columns) { 00584 $columns = '*'; 00585 } else { 00586 $column_list = array(); 00587 foreach($output->columns as $key => $val) { 00588 $name = $val['name']; 00589 $alias = $val['alias']; 00590 if($val['click_count']) $click_count[] = $val['name']; 00591 00592 if(substr($name,-1) == '*') { 00593 $column_list[] = $name; 00594 } elseif(strpos($name,'.')===false && strpos($name,'(')===false) { 00595 if($alias) $column_list[] = sprintf('%s as %s', $name, $alias); 00596 else $column_list[] = sprintf('%s',$name); 00597 } else { 00598 if($alias) $column_list[] = sprintf('%s as %s', $name, $alias); 00599 else $column_list[] = sprintf('%s',$name); 00600 } 00601 } 00602 $columns = implode(',',$column_list); 00603 } 00604 00605 $condition = $this->getCondition($output); 00606 00607 if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output); 00608 00609 // list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가 00610 if($output->order) { 00611 $conditions = $this->getConditionList($output); 00612 if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) { 00613 foreach($output->order as $key => $val) { 00614 $col = $val[0]; 00615 if(!in_array($col, array('list_order','update_order'))) continue; 00616 if($condition) $condition .= sprintf(' and %s < 2100000000 ', $col); 00617 else $condition = sprintf(' where %s < 2100000000 ', $col); 00618 } 00619 } 00620 } 00621 00622 $query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition); 00623 00624 if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups)); 00625 00626 if($output->order) { 00627 foreach($output->order as $key => $val) { 00628 $index_list[] = sprintf('%s %s', $val[0], $val[1]); 00629 } 00630 if(count($index_list)) $query .= ' order by '.implode(',',$index_list); 00631 } 00632 00633 // list_count를 사용할 경우 적용 00634 if($output->list_count['value']) $query = sprintf('%s limit %d', $query, $output->list_count['value']); 00635 00636 $this->_prepare($query); 00637 $data = $this->_execute(); 00638 if($this->isError()) return; 00639 00640 if(count($click_count)>0 && count($output->conditions)>0){ 00641 $_query = ''; 00642 foreach($click_count as $k => $c) $_query .= sprintf(',%s=%s+1 ',$c,$c); 00643 $_query = sprintf('update %s set %s %s',implode(',',$table_list), substr($_query,1), $condition); 00644 $this->_query($_query); 00645 } 00646 00647 $buff = new Object(); 00648 $buff->data = $data; 00649 return $buff; 00650 }
| DBSqlite3_pdo::_executeUpdateAct | ( | $ | output | ) |
updateAct 처리
DBSqlite3_pdo.class.php 파일의 475 번째 라인에서 정의되었습니다.
00475 { 00476 $table_count = count(array_values($output->tables)); 00477 00478 // 대상 테이블이 1개일 경우 00479 if($table_count == 1) { 00480 // 테이블 정리 00481 list($target_table) = array_values($output->tables); 00482 $target_table = $this->prefix.$target_table; 00483 00484 // 컬럼 정리 00485 foreach($output->columns as $key => $val) { 00486 if(!isset($val['value'])) continue; 00487 $name = $val['name']; 00488 $value = $val['value']; 00489 if(strpos($name,'.')!==false&&strpos($value,'.')!==false) $column_list[] = $name.' = '.$value; 00490 else { 00491 if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'"; 00492 elseif(!$value || is_numeric($value)) $value = (int)$value; 00493 00494 $column_list[] = sprintf("%s = %s", $name, $value); 00495 } 00496 } 00497 00498 // 조건절 정리 00499 $condition = $this->getCondition($output); 00500 00501 $query = sprintf("update %s set %s %s", $target_table, implode(',',$column_list), $condition); 00502 00503 // 대상 테이블이 2개일 경우 (sqlite에서 update 테이블을 1개 이상 지정 못해서 이렇게 꽁수로... 다른 방법이 있으려나..) 00504 } elseif($table_count == 2) { 00505 // 테이블 정리 00506 foreach($output->tables as $key => $val) { 00507 $table_list[$val] = $this->prefix.$key; 00508 } 00509 list($source_table, $target_table) = array_values($table_list); 00510 00511 // 조건절 정리 00512 $condition = $this->getCondition($output); 00513 foreach($table_list as $key => $val) { 00514 $condition = eregi_replace($key.'\\.', $val.'.', $condition); 00515 } 00516 00517 // 컬럼 정리 00518 foreach($output->columns as $key => $val) { 00519 if(!isset($val['value'])) continue; 00520 $name = $val['name']; 00521 $value = $val['value']; 00522 list($s_prefix, $s_column) = explode('.',$name); 00523 list($t_prefix, $t_column) = explode('.',$value); 00524 00525 $s_table = $table_list[$s_prefix]; 00526 $t_table = $table_list[$t_prefix]; 00527 $column_list[] = sprintf(' %s = (select %s from %s %s) ', $s_column, $t_column, $t_table, $condition); 00528 } 00529 00530 $query = sprintf('update %s set %s where exists(select * from %s %s)', $source_table, implode(',', $column_list), $target_table, $condition); 00531 } else { 00532 return; 00533 } 00534 00535 $this->_prepare($query); 00536 return $this->_execute(); 00537 }
| DBSqlite3_pdo::_getCondition | ( | $ | conditions, | |
| $ | column_type | |||
| ) |
DBSqlite3_pdo.class.php 파일의 408 번째 라인에서 정의되었습니다.
00408 { 00409 $condition = ''; 00410 foreach($conditions as $val) { 00411 $sub_condition = ''; 00412 foreach($val['condition'] as $v) { 00413 if(!isset($v['value'])) continue; 00414 if($v['value'] === '') continue; 00415 if(!in_array(gettype($v['value']), array('string', 'integer'))) continue; 00416 00417 $name = $v['column']; 00418 $operation = $v['operation']; 00419 $value = $v['value']; 00420 $type = $this->getColumnType($column_type,$name); 00421 $pipe = $v['pipe']; 00422 00423 $value = $this->getConditionValue($name, $value, $operation, $type, $column_type); 00424 if(!$value) $value = $v['value']; 00425 $str = $this->getConditionPart($name, $value, $operation); 00426 if($sub_condition) $sub_condition .= ' '.$pipe.' '; 00427 $sub_condition .= $str; 00428 } 00429 if($sub_condition) { 00430 if($condition && $val['pipe']) $condition .= ' '.$val['pipe'].' '; 00431 $condition .= '('.$sub_condition.')'; 00432 } 00433 } 00434 return $condition; 00435 }
| DBSqlite3_pdo::_getNavigationData | ( | $ | table_list, | |
| $ | columns, | |||
| $ | left_join, | |||
| $ | condition, | |||
| $ | output | |||
| ) |
query xml에 navigation 정보가 있을 경우 페이징 관련 작업을 처리한다
그닥 좋지는 않은 구조이지만 편리하다.. -_-;
DBSqlite3_pdo.class.php 파일의 657 번째 라인에서 정의되었습니다.
00657 { 00658 require_once(_XE_PATH_.'classes/page/PageHandler.class.php'); 00659 00660 /* 00661 // group by 절이 포함된 SELECT 쿼리의 전체 갯수를 구하기 위한 수정 00662 // 정상적인 동작이 확인되면 주석으로 막아둔 부분으로 대체합니다. 00663 // 00664 $count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition; 00665 $total_count = $this->getCountCache($output->tables, $count_condition); 00666 if($total_count === false) { 00667 $count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition); 00668 if (count($output->groups)) 00669 $count_query = sprintf('select count(*) as count from (%s) xet', $count_query); 00670 $result = $this->_query($count_query); 00671 $count_output = $this->_fetch($result); 00672 $total_count = (int)$count_output->count; 00673 $this->putCountCache($output->tables, $count_condition, $total_count); 00674 } 00675 */ 00676 00677 // 전체 개수를 구함 00678 $count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition); 00679 $total_count = $this->getCountCache($output->tables, $condition); 00680 if($total_count === false) { 00681 $this->_prepare($count_query); 00682 $count_output = $this->_execute(); 00683 $total_count = (int)$count_output->count; 00684 $this->putCountCache($output->tables, $condition, $total_count); 00685 } 00686 00687 $list_count = $output->list_count['value']; 00688 if(!$list_count) $list_count = 20; 00689 $page_count = $output->page_count['value']; 00690 if(!$page_count) $page_count = 10; 00691 $page = $output->page['value']; 00692 if(!$page) $page = 1; 00693 00694 // 전체 페이지를 구함 00695 if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1; 00696 else $total_page = 1; 00697 00698 // 페이지 변수를 체크 00699 if($page > $total_page) $page = $total_page; 00700 $start_count = ($page-1)*$list_count; 00701 00702 // list_order, update_order 로 정렬시에 인덱스 사용을 위해 condition에 쿼리 추가 00703 if($output->order) { 00704 $conditions = $this->getConditionList($output); 00705 if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) { 00706 foreach($output->order as $key => $val) { 00707 $col = $val[0]; 00708 if(!in_array($col, array('list_order','update_order'))) continue; 00709 if($condition) $condition .= sprintf(' and %s < 2100000000 ', $col); 00710 else $condition = sprintf(' where %s < 2100000000 ', $col); 00711 } 00712 } 00713 } 00714 00715 $query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition); 00716 00717 if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups)); 00718 00719 if($output->order) { 00720 foreach($output->order as $key => $val) { 00721 $index_list[] = sprintf('%s %s', $val[0], $val[1]); 00722 } 00723 if(count($index_list)) $query .= ' order by '.implode(',',$index_list); 00724 } 00725 00726 // return 결과물 생성 00727 $buff = new Object(); 00728 $buff->total_count = 0; 00729 $buff->total_page = 0; 00730 $buff->page = 1; 00731 $buff->data = array(); 00732 $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); 00733 00734 // 쿼리 실행 00735 $query = sprintf('%s limit %d, %d', $query, $start_count, $list_count); 00736 $this->_prepare($query); 00737 00738 if($this->isError()) { 00739 $this->setError($this->handler->errorCode(), print_r($this->handler->errorInfo(),true)); 00740 $this->actFinish(); 00741 return $buff; 00742 } 00743 00744 $this->stmt->execute(); 00745 00746 if($this->stmt->errorCode() != '00000') { 00747 $this->setError($this->stmt->errorCode(), print_r($this->stmt->errorInfo(),true)); 00748 $this->actFinish(); 00749 return $buff; 00750 } 00751 00752 $output = null; 00753 $virtual_no = $total_count - ($page-1)*$list_count; 00754 while($tmp = $this->stmt->fetch(PDO::FETCH_ASSOC)) { 00755 unset($obj); 00756 foreach($tmp as $key => $val) { 00757 $pos = strpos($key, '.'); 00758 if($pos) $key = substr($key, $pos+1); 00759 $obj->{$key} = $val; 00760 } 00761 $data[$virtual_no--] = $obj; 00762 } 00763 00764 $this->stmt = null; 00765 $this->actFinish(); 00766 00767 $buff = new Object(); 00768 $buff->total_count = $total_count; 00769 $buff->total_page = $total_page; 00770 $buff->page = $page; 00771 $buff->data = $data; 00772 00773 $buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count); 00774 return $buff; 00775 }
| DBSqlite3_pdo::_prepare | ( | $ | query | ) |
: 쿼리문의 prepare
DBSqlite3_pdo.class.php 파일의 135 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::$query, DB::actFinish(), DB::actStart(), DB::isConnected(), DB::setError().
00135 { 00136 if(!$this->isConnected()) return; 00137 00138 // 쿼리 시작을 알림 00139 $this->actStart($query); 00140 00141 $this->stmt = $this->handler->prepare($query); 00142 00143 if($this->handler->errorCode() != '00000') { 00144 $this->setError($this->handler->errorCode(), print_r($this->handler->errorInfo(),true)); 00145 $this->actFinish(); 00146 } 00147 $this->bind_idx = 0; 00148 $this->bind_vars = array(); 00149 }

| DBSqlite3_pdo::_setDBInfo | ( | ) |
DB정보 설정 및 connect/ close.
DBSqlite3_pdo.class.php 파일의 61 번째 라인에서 정의되었습니다.
다음을 참조함 : Context::getDBInfo().
다음에 의해서 참조됨 : DBSqlite3_pdo().
00061 { 00062 $db_info = Context::getDBInfo(); 00063 $this->database = $db_info->db_database; 00064 $this->prefix = $db_info->db_table_prefix; 00065 if(!substr($this->prefix,-1)!='_') $this->prefix .= '_'; 00066 }

| DBSqlite3_pdo::addColumn | ( | $ | table_name, | |
| $ | column_name, | |||
| $ | type = 'number', |
|||
| $ | size = '', |
|||
| $ | default = '', |
|||
| $ | notnull = false | |||
| ) |
특정 테이블에 특정 column 추가
DBSqlite3_pdo.class.php 파일의 222 번째 라인에서 정의되었습니다.
00222 { 00223 $type = $this->column_type[$type]; 00224 if(strtoupper($type)=='INTEGER') $size = ''; 00225 00226 $query = sprintf("alter table %s%s add %s ", $this->prefix, $table_name, $column_name); 00227 if($size) $query .= sprintf(" %s(%s) ", $type, $size); 00228 else $query .= sprintf(" %s ", $type); 00229 if($default) $query .= sprintf(" default '%s' ", $default); 00230 if($notnull) $query .= " not null "; 00231 00232 $this->_prepare($query); 00233 return $this->_execute(); 00234 }
| DBSqlite3_pdo::addIndex | ( | $ | table_name, | |
| $ | index_name, | |||
| $ | target_columns, | |||
| $ | is_unique = false | |||
| ) |
특정 테이블에 특정 인덱스 추가 $target_columns = array(col1, col2) $is_unique? unique : none
DBSqlite3_pdo.class.php 파일의 267 번째 라인에서 정의되었습니다.
00267 { 00268 if(!is_array($target_columns)) $target_columns = array($target_columns); 00269 00270 $key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name); 00271 00272 $query = sprintf('CREATE %s INDEX %s ON %s%s (%s)', $is_unique?'UNIQUE':'', $key_name, $this->prefix, $table_name, implode(',',$target_columns)); 00273 $this->_prepare($query); 00274 $this->_execute(); 00275 }
| DBSqlite3_pdo::addQuotes | ( | $ | string | ) |
쿼리에서 입력되는 문자열 변수들의 quotation 조절
DBSqlite3_pdo.class.php 파일의 126 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::begin | ( | ) |
트랜잭션 시작
DBSqlite3_pdo.class.php 파일의 100 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::isConnected().
00100 { 00101 if(!$this->isConnected() || $this->transaction_started) return; 00102 if($this->handler->beginTransaction()) $this->transaction_started = true; 00103 }

| DBSqlite3_pdo::close | ( | ) |
DB접속 해제.
DBSqlite3_pdo.class.php 파일의 92 번째 라인에서 정의되었습니다.
다음을 참조함 : commit(), DB::isConnected().
00092 { 00093 if(!$this->isConnected()) return; 00094 $this->commit(); 00095 }

| DBSqlite3_pdo::commit | ( | $ | force = false |
) |
커밋
DBSqlite3_pdo.class.php 파일의 117 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::isConnected().
다음에 의해서 참조됨 : close().
00117 { 00118 if(!$force && (!$this->isConnected() || !$this->transaction_started)) return; 00119 $this->handler->commit(); 00120 $this->transaction_started = false; 00121 }

| DBSqlite3_pdo::createTableByXml | ( | $ | xml_doc | ) |
xml 을 받아서 테이블을 생성
DBSqlite3_pdo.class.php 파일의 302 번째 라인에서 정의되었습니다.
00302 { 00303 return $this->_createTable($xml_doc); 00304 }
| DBSqlite3_pdo::createTableByXmlFile | ( | $ | file_name | ) |
xml 을 받아서 테이블을 생성
DBSqlite3_pdo.class.php 파일의 309 번째 라인에서 정의되었습니다.
다음을 참조함 : FileHandler::readFile().
00309 { 00310 if(!file_exists($file_name)) return; 00311 // xml 파일을 읽음 00312 $buff = FileHandler::readFile($file_name); 00313 return $this->_createTable($buff); 00314 }

| DBSqlite3_pdo::DBSqlite3_pdo | ( | ) |
constructor
DBSqlite3_pdo.class.php 파일의 45 번째 라인에서 정의되었습니다.
다음을 참조함 : _connect(), _setDBInfo().
00045 { 00046 $this->_setDBInfo(); 00047 $this->_connect(); 00048 }

| DBSqlite3_pdo::dropColumn | ( | $ | table_name, | |
| $ | column_name | |||
| ) |
특정 테이블에 특정 column 제거
DBSqlite3_pdo.class.php 파일의 239 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::dropIndex | ( | $ | table_name, | |
| $ | index_name, | |||
| $ | is_unique = false | |||
| ) |
특정 테이블의 특정 인덱스 삭제
DBSqlite3_pdo.class.php 파일의 280 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::getCondition | ( | $ | output | ) |
조건문 작성하여 return
DBSqlite3_pdo.class.php 파일의 396 번째 라인에서 정의되었습니다.
다음을 참조함 : $output.
00396 { 00397 if(!$output->conditions) return; 00398 $condition = $this->_getCondition($output->conditions,$output->column_type); 00399 if($condition) $condition = ' where '.$condition; 00400 return $condition; 00401 }
| DBSqlite3_pdo::getLeftCondition | ( | $ | conditions, | |
| $ | column_type | |||
| ) |
DBSqlite3_pdo.class.php 파일의 403 번째 라인에서 정의되었습니다.
00403 { 00404 return $this->_getCondition($conditions,$column_type); 00405 }
| DBSqlite3_pdo::getNextSequence | ( | ) |
1씩 증가되는 sequence값을 return
DBSqlite3_pdo.class.php 파일의 195 번째 라인에서 정의되었습니다.
00195 { 00196 $query = sprintf("insert into %ssequence (seq) values (NULL)", $this->prefix); 00197 $this->_prepare($query); 00198 $result = $this->_execute(); 00199 $sequence = $this->handler->lastInsertId(); 00200 if($sequence % 10000 == 0) { 00201 $query = sprintf("delete from %ssequence where seq < %d", $this->prefix, $sequence); 00202 $this->_prepare($query); 00203 $result = $this->_execute(); 00204 } 00205 00206 return $sequence; 00207 }
| DBSqlite3_pdo::isColumnExists | ( | $ | table_name, | |
| $ | column_name | |||
| ) |
특정 테이블의 column의 정보를 return
DBSqlite3_pdo.class.php 파일의 247 번째 라인에서 정의되었습니다.
다음을 참조함 : $output.
00247 { 00248 $query = sprintf("pragma table_info(%s%s)", $this->prefix, $table_name); 00249 $this->_prepare($query); 00250 $output = $this->_execute(); 00251 00252 if($output) { 00253 $column_name = strtolower($column_name); 00254 foreach($output as $key => $val) { 00255 $name = strtolower($val->name); 00256 if($column_name == $name) return true; 00257 } 00258 } 00259 return false; 00260 }
| DBSqlite3_pdo::isIndexExists | ( | $ | table_name, | |
| $ | index_name | |||
| ) |
| DBSqlite3_pdo::isSupported | ( | ) |
설치 가능 여부를 return
DBSqlite3_pdo.class.php 파일의 53 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::isTableExists | ( | $ | target_name | ) |
| DBSqlite3_pdo::rollback | ( | ) |
롤백
DBSqlite3_pdo.class.php 파일의 108 번째 라인에서 정의되었습니다.
다음을 참조함 : DB::isConnected().
00108 { 00109 if(!$this->isConnected() || !$this->transaction_started) return; 00110 $this->handler->rollBack(); 00111 $this->transaction_started = false; 00112 }

| DBSqlite3_pdo::$bind_idx = 0 |
DBSqlite3_pdo.class.php 파일의 22 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::$bind_vars = array() |
DBSqlite3_pdo.class.php 파일의 23 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::$column_type |
array(
'bignumber' => 'INTEGER',
'number' => 'INTEGER',
'varchar' => 'VARHAR',
'char' => 'CHAR',
'text' => 'TEXT',
'bigtext' => 'TEXT',
'date' => 'VARCHAR(14)',
'float' => 'REAL',
)
sqlite3 에서 사용될 column type
column_type은 schema/query xml에서 공통 선언된 type을 이용하기 때문에 각 DBMS에 맞게 replace 해주어야 한다
DBSqlite3_pdo.class.php 파일의 31 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::$database = NULL |
| DBSqlite3_pdo::$handler = NULL |
PDO 사용시 필요한 변수들
DBSqlite3_pdo.class.php 파일의 20 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::$prefix = 'xe' |
XE에서 사용할 테이블들의 prefix (한 DB에서 여러개의 XE 설치 가능).
DBSqlite3_pdo.class.php 파일의 15 번째 라인에서 정의되었습니다.
| DBSqlite3_pdo::$stmt = NULL |
DBSqlite3_pdo.class.php 파일의 21 번째 라인에서 정의되었습니다.
1.6.1