질문Q #8256
sqlite3_driver.php에 list_fields() 추가하기
letsgolee2014-07-19 09:21:33
Codeigniter 3.0을 사용하면서 mysql로 작업하던 것을 sqlite3로 옮겨올 때 함수 처리가 문제가 되더라구요. 예를 든다면 Tank_Auth에서 Unix_timestamp()함수를 쓰는데 sqlite3에는 이게 지원되지 않습니다. 그래서 파일을 수정해서 strftime('%s', field_name)이런 식으로 지원되게 하는 방향으로 했는데 또 에러가 나서 로그를 보니 list_fields를 쓰는 곳에서 에러가 납니다. 소스를 뜯어보니 sqlite3에서는 _list_columns() 결과가 false가 되어 list_fields가 지원이 안되는 겁니다. 문제는 field_data()는 지원되면서... 그래서 이 함수를 이용해 list_fields()를 만들어 보았습니다.

이 함수를 sqlite3_driver.php 안에 넣어주시면 됩니다.
 
	/**
	 * Fetch Field Names
	 *
	 * @param	string	the table name
	 * @return	array
	 */
	public function list_fields($table = '')
	{
		// Is there a cached result?
		if (isset($this->data_cache['field_names'][$table]))
		{
			return $this->data_cache['field_names'][$table];
		}

		if ($table === '')
		{
			return ($this->db_debug) ? $this->display_error('db_field_param_missing') : FALSE;
		}

		$result = $this->field_data($table);
		$this->data_cache['field_names'][$table] = array();

		foreach ($result as $row)
		{
			$this->data_cache['field_names'][$table][] = $row->name;
		}

		return $this->data_cache['field_names'][$table];
	}
답변2
#1 변종원(웅파) 2014-07-21 10:07:58
팁 감사합니다. ^^
#2 한대승(불의회상) 2014-07-21 13:38:53
좋은 정보 감사 합니다.