datadict-sqlite.inc.php 3.2 KB
Newer Older
doctrine's avatar
doctrine committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/**
  V4.65 22 July 2005  (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved.
  Released under both BSD license and Lesser GPL library license. 
  Whenever there is any discrepancy between the two licenses, 
  the BSD license will take precedence.
	
  Set tabs to 4 for best viewing.
  
  Modified 28 August, 2005 for use with ADOdb Lite by Mark Dickenson
  
*/

// security - hide paths
if (!defined('ADODB_DIR')) die();

class ADODB2_sqlite extends ADODB_DataDict {

	var $dbtype = 'sqlite';
	var $seqField = false;

	var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";

 	function ActualType($meta)
	{
		switch($meta) {
27
		case 'C': return 'TEXT';
doctrine's avatar
doctrine committed
28
		case 'XL':
29
		case 'X': return 'TEXT';
doctrine's avatar
doctrine committed
30
		
31 32 33 34
		case 'C2': return 'TEXT';
		case 'X2': return 'TEXT';

		case 'B': return 'BLOB';
doctrine's avatar
doctrine committed
35 36 37 38
			
		case 'D': return 'DATE';
		case 'T': return 'DATE';
		
zYne's avatar
zYne committed
39
		case 'L': return 'INTEGER';
40 41 42 43 44
		case 'I': return 'INTEGER';
		case 'I1': return 'INTEGER';
		case 'I2': return 'INTEGER';
		case 'I4': return 'INTEGER';
		case 'I8': return 'INTEGER';
doctrine's avatar
doctrine committed
45
		
46
		case 'F': return 'REAL';
doctrine's avatar
doctrine committed
47 48 49 50 51
		case 'N': return 'DECIMAL';
		default:
			return $meta;
		}
	}
52
	// return string must begin with space
53 54

	function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned = null)
55 56 57 58 59
	{	
		$suffix = '';
		if ($funsigned) $suffix .= ' UNSIGNED';
		if ($fnotnull) $suffix .= ' NOT NULL';
		if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
60

61 62 63 64 65
		if ($fautoinc) $suffix .= ' PRIMARY KEY AUTOINCREMENT';
		if ($fconstraint) $suffix .= ' '.$fconstraint;
		return $suffix;
	}

66
	function _TableSQL($tabname, $lines,$pkey,$tableoptions)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	{
		$sql = array();

		if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
			$sql[] = sprintf($this->dropTable,$tabname);
			if ($this->autoIncrement) {
				$sInc = $this->_DropAutoIncrement($tabname);
				if ($sInc) $sql[] = $sInc;
			}
			if ( isset ($tableoptions['DROP']) ) {
				return $sql;
			}
		}
		$s = "CREATE TABLE $tabname (\n";
		$s .= implode(",\n", $lines);
82 83

		if (sizeof($pkey)>0 && ! $this->autoIncrement) {
84 85 86
			$s .= ",\n				 PRIMARY KEY (";
			$s .= implode(", ",$pkey).")";
		}
87

88 89 90 91 92 93 94 95 96 97 98 99
        if (isset($tableoptions['CONSTRAINTS']))
			$s .= "\n".$tableoptions['CONSTRAINTS'];

		if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) 
			$s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];

		$s .= "\n)";
		if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
		$sql[] = $s;

		return $sql;
	}
doctrine's avatar
doctrine committed
100

101
	function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
doctrine's avatar
doctrine committed
102 103 104 105 106 107
	{
		if ($this->debug) $this->outp("AlterColumnSQL not supported");
		return array();
	}
	
	
108
	function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
doctrine's avatar
doctrine committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
	{
		if ($this->debug) $this->outp("DropColumnSQL not supported");
		return array();
	}

//	function MetaType($t,$len=-1,$fieldobj=false)
//	{
//	}

//	function &MetaTables($ttype=false,$showSchema=false,$mask=false) 
//	{
//		global $ADODB_FETCH_MODE;
//	}

//	function &MetaColumns($table,$upper=true) 
//	{
//		global $ADODB_FETCH_MODE;
//	}

//	function MetaPrimaryKeys($table, $owner=false)
//	{
//	}

//     function &MetaIndexes($table, $primary = false, $owner = false)
//     {
//     }

}

138