Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding latest ADOdb to stable

  • Loading branch information...
commit 00231a7498f316cbf6cc630d52d789f6190e8985 1 parent ad6c367
authored July 16, 2004

Showing 66 changed files with 21,272 additions and 20,621 deletions. Show diff stats Hide diff stats

  1. 468  lib/adodb/adodb-csvlib.inc.php
  2. 1,339  lib/adodb/adodb-datadict.inc.php
  3. 508  lib/adodb/adodb-error.inc.php
  4. 157  lib/adodb/adodb-errorhandler.inc.php
  5. 174  lib/adodb/adodb-errorpear.inc.php
  6. 155  lib/adodb/adodb-exceptions.inc.php
  7. 138  lib/adodb/adodb-iterator.inc.php
  8. 1,252  lib/adodb/adodb-lib.inc.php
  9. 569  lib/adodb/adodb-pager.inc.php
  10. 722  lib/adodb/adodb-pear.inc.php
  11. 1,810  lib/adodb/adodb-perf.inc.php
  12. 30  lib/adodb/adodb-php4.inc.php
  13. 82  lib/adodb/adodb-time.inc.php
  14. BIN  lib/adodb/adodb-time.zip
  15. 7,349  lib/adodb/adodb.inc.php
  16. 185  lib/adodb/datadict/datadict-access.inc.php
  17. 148  lib/adodb/datadict/datadict-db2.inc.php
  18. 245  lib/adodb/datadict/datadict-generic.inc.php
  19. 129  lib/adodb/datadict/datadict-ibase.inc.php
  20. 155  lib/adodb/datadict/datadict-informix.inc.php
  21. 477  lib/adodb/datadict/datadict-mssql.inc.php
  22. 353  lib/adodb/datadict/datadict-mysql.inc.php
  23. 538  lib/adodb/datadict/datadict-oci8.inc.php
  24. 429  lib/adodb/datadict/datadict-postgres.inc.php
  25. 451  lib/adodb/datadict/datadict-sybase.inc.php
  26. 163  lib/adodb/drivers/adodb-access.inc.php
  27. 1,231  lib/adodb/drivers/adodb-ado.inc.php
  28. 93  lib/adodb/drivers/adodb-ado_access.inc.php
  29. 157  lib/adodb/drivers/adodb-ado_mssql.inc.php
  30. 168  lib/adodb/drivers/adodb-borland_ibase.inc.php
  31. 401  lib/adodb/drivers/adodb-csv.inc.php
  32. 627  lib/adodb/drivers/adodb-db2.inc.php
  33. 525  lib/adodb/drivers/adodb-fbsql.inc.php
  34. 142  lib/adodb/drivers/adodb-firebird.inc.php
  35. 1,669  lib/adodb/drivers/adodb-ibase.inc.php
  36. 62  lib/adodb/drivers/adodb-informix.inc.php
  37. 795  lib/adodb/drivers/adodb-informix72.inc.php
  38. 1,857  lib/adodb/drivers/adodb-mssql.inc.php
  39. 119  lib/adodb/drivers/adodb-mssqlpo.inc.php
  40. 1,349  lib/adodb/drivers/adodb-mysql.inc.php
  41. 1,628  lib/adodb/drivers/adodb-mysqli.inc.php
  42. 153  lib/adodb/drivers/adodb-mysqlt.inc.php
  43. 2,417  lib/adodb/drivers/adodb-oci8.inc.php
  44. 113  lib/adodb/drivers/adodb-oci805.inc.php
  45. 381  lib/adodb/drivers/adodb-oci8po.inc.php
  46. 1,424  lib/adodb/drivers/adodb-odbc.inc.php
  47. 479  lib/adodb/drivers/adodb-odbc_mssql.inc.php
  48. 230  lib/adodb/drivers/adodb-odbc_oracle.inc.php
  49. 617  lib/adodb/drivers/adodb-oracle.inc.php
  50. 26  lib/adodb/drivers/adodb-postgres.inc.php
  51. 1,912  lib/adodb/drivers/adodb-postgres64.inc.php
  52. 379  lib/adodb/drivers/adodb-postgres7.inc.php
  53. 61  lib/adodb/drivers/adodb-proxy.inc.php
  54. 127  lib/adodb/drivers/adodb-sapdb.inc.php
  55. 335  lib/adodb/drivers/adodb-sqlanywhere.inc.php
  56. 639  lib/adodb/drivers/adodb-sqlite.inc.php
  57. 813  lib/adodb/drivers/adodb-sybase.inc.php
  58. 204  lib/adodb/drivers/adodb-vfp.inc.php
  59. 362  lib/adodb/license.txt
  60. 200  lib/adodb/perf/perf-db2.inc.php
  61. 137  lib/adodb/perf/perf-informix.inc.php
  62. 323  lib/adodb/perf/perf-mssql.inc.php
  63. 513  lib/adodb/perf/perf-mysql.inc.php
  64. 958  lib/adodb/perf/perf-oci8.inc.php
  65. 241  lib/adodb/perf/perf-postgres.inc.php
468  lib/adodb/adodb-csvlib.inc.php
... ...
@@ -1,218 +1,252 @@
1  
-<?php
2  
-global $ADODB_INCLUDED_CSV;
3  
-$ADODB_INCLUDED_CSV = 1;
4  
-
5  
-/* 
6  
-  V4.20 22 Feb 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
7  
-  Released under both BSD license and Lesser GPL library license. 
8  
-  Whenever there is any discrepancy between the two licenses, 
9  
-  the BSD license will take precedence. See License.txt. 
10  
-  Set tabs to 4 for best viewing.
11  
-  
12  
-  Latest version is available at http://php.weblogs.com/
13  
-  
14  
-  Library for CSV serialization. This is used by the csv/proxy driver and is the 
15  
-  CacheExecute() serialization format. 
16  
-  
17  
-  ==== NOTE ====
18  
-  Format documented at http://php.weblogs.com/ADODB_CSV
19  
-  ==============
20  
-*/
21  
-
22  
-	/**
23  
- 	 * convert a recordset into special format
24  
-	 *
25  
-	 * @param rs	the recordset
26  
-	 *
27  
-	 * @return	the CSV formated data
28  
-	 */
29  
-	function _rs2serialize(&$rs,$conn=false,$sql='')
30  
-	{
31  
-		$max = ($rs) ? $rs->FieldCount() : 0;
32  
-		
33  
-		if ($sql) $sql = urlencode($sql);
34  
-		// metadata setup
35  
-		
36  
-		if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
37  
-			if (is_object($conn)) {
38  
-				$sql .= ','.$conn->Affected_Rows();
39  
-				$sql .= ','.$conn->Insert_ID();
40  
-			} else
41  
-				$sql .= ',,';
42  
-			
43  
-			$text = "====-1,0,$sql\n";
44  
-			return $text;
45  
-		} else {
46  
-			$tt = ($rs->timeCreated) ? $rs->timeCreated : time();
47  
-			$line = "====0,$tt,$sql\n";
48  
-		}
49  
-		// column definitions
50  
-		for($i=0; $i < $max; $i++) {
51  
-			$o = $rs->FetchField($i);
52  
-			$line .= urlencode($o->name).':'.$rs->MetaType($o->type,$o->max_length,$o).":$o->max_length,";
53  
-		}
54  
-		$text = substr($line,0,strlen($line)-1)."\n";
55  
-		
56  
-		
57  
-		// get data
58  
-		if ($rs->databaseType == 'array') {
59  
-			$text .= serialize($rs->_array);
60  
-		} else {
61  
-			$rows = array();
62  
-			while (!$rs->EOF) {	
63  
-				$rows[] = $rs->fields;
64  
-				$rs->MoveNext();
65  
-			} 
66  
-			$text .= serialize($rows);
67  
-		}
68  
-		$rs->MoveFirst();
69  
-		return $text;
70  
-	}
71  
-
72  
-	
73  
-/**
74  
-* Open CSV file and convert it into Data. 
75  
-*
76  
-* @param url  		file/ftp/http url
77  
-* @param err		returns the error message
78  
-* @param timeout	dispose if recordset has been alive for $timeout secs
79  
-*
80  
-* @return		recordset, or false if error occured. If no
81  
-*			error occurred in sql INSERT/UPDATE/DELETE, 
82  
-*			empty recordset is returned
83  
-*/
84  
-	function &csv2rs($url,&$err,$timeout=0)
85  
-	{
86  
-		$err = false;
87  
-		$fp = @fopen($url,'r');
88  
-		if (!$fp) {
89  
-			$err = $url.' file/URL not found';
90  
-			return false;
91  
-		}
92  
-		flock($fp, LOCK_SH);
93  
-		$arr = array();
94  
-		$ttl = 0;
95  
-		
96  
-		if ($meta = fgetcsv ($fp, 32000, ",")) {
97  
-			// check if error message
98  
-			if (substr($meta[0],0,4) === '****') {
99  
-				$err = trim(substr($meta[0],4,1024));
100  
-				fclose($fp);
101  
-				return false;
102  
-			}
103  
-			// check for meta data
104  
-			// $meta[0] is -1 means return an empty recordset
105  
-			// $meta[1] contains a time 
106  
-	
107  
-			if (substr($meta[0],0,4) ===  '====') {
108  
-			
109  
-				if ($meta[0] == "====-1") {
110  
-					if (sizeof($meta) < 5) {
111  
-						$err = "Corrupt first line for format -1";
112  
-						fclose($fp);
113  
-						return false;
114  
-					}
115  
-					fclose($fp);
116  
-					
117  
-					if ($timeout > 0) {
118  
-						$err = " Illegal Timeout $timeout ";
119  
-						return false;
120  
-					}
121  
-					$rs->fields = array();
122  
-					$rs->timeCreated = $meta[1];
123  
-					$rs = new ADORecordSet($val=true);
124  
-					$rs->EOF = true;
125  
-					$rs->_numOfFields=0;
126  
-					$rs->sql = urldecode($meta[2]);
127  
-					$rs->affectedrows = (integer)$meta[3];
128  
-					$rs->insertid = $meta[4];	
129  
-					return $rs;
130  
-				}
131  
-			# Under high volume loads, we want only 1 thread/process to _write_file
132  
-			# so that we don't have 50 processes queueing to write the same data.
133  
-			# Would require probabilistic blocking write 
134  
-			#
135  
-			# -2 sec before timeout, give processes 1/16 chance of writing to file with blocking io
136  
-			# -1 sec after timeout give processes 1/4 chance of writing with blocking
137  
-			# +0 sec after timeout, give processes 100% chance writing with blocking
138  
-				if (sizeof($meta) > 1) {
139  
-					if($timeout >0){ 
140  
-						$tdiff = $meta[1]+$timeout - time();
141  
-						if ($tdiff <= 2) {
142  
-							switch($tdiff) {
143  
-							case 2: 
144  
-								if ((rand() & 15) == 0) {
145  
-									fclose($fp);
146  
-									$err = "Timeout 2";
147  
-									return false;
148  
-								}
149  
-								break;
150  
-							case 1:
151  
-								if ((rand() & 3) == 0) {
152  
-									fclose($fp);
153  
-									$err = "Timeout 1";
154  
-									return false;
155  
-								}
156  
-								break;
157  
-							default: 
158  
-								fclose($fp);
159  
-								$err = "Timeout 0";
160  
-								return false;
161  
-							} // switch
162  
-							
163  
-						} // if check flush cache
164  
-					}// (timeout>0)
165  
-					$ttl = $meta[1];
166  
-				}
167  
-				$meta = false;
168  
-				$meta = fgetcsv($fp, 16000, ",");
169  
-				if (!$meta) {
170  
-					fclose($fp);
171  
-					$err = "Unexpected EOF 1";
172  
-					return false;
173  
-				}
174  
-			}
175  
-
176  
-			// Get Column definitions
177  
-			$flds = array();
178  
-			foreach($meta as $o) {
179  
-				$o2 = explode(':',$o);
180  
-				if (sizeof($o2)!=3) {
181  
-					$arr[] = $meta;
182  
-					$flds = false;
183  
-					break;
184  
-				}
185  
-				$fld = new ADOFieldObject();
186  
-				$fld->name = urldecode($o2[0]);
187  
-				$fld->type = $o2[1];
188  
-				$fld->max_length = $o2[2];
189  
-				$flds[] = $fld;
190  
-			}
191  
-		} else {
192  
-			fclose($fp);
193  
-			$err = "Recordset had unexpected EOF 2";
194  
-			return false;
195  
-		}
196  
-		
197  
-		// slurp in the data
198  
-		$MAXSIZE = 128000;
199  
-		
200  
-		$text = '';
201  
-		while ($txt = fread($fp,$MAXSIZE)) {
202  
-			$text .= $txt;
203  
-		}
204  
-			
205  
-		fclose($fp);
206  
-		$arr = @unserialize($text);
207  
-		//var_dump($arr);
208  
-		if (!is_array($arr)) {
209  
-			$err = "Recordset had unexpected EOF (in serialized recordset)";
210  
-			if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!";
211  
-			return false;
212  
-		}
213  
-		$rs = new ADORecordSet_array();
214  
-		$rs->timeCreated = $ttl;
215  
-		$rs->InitArrayFields($arr,$flds);
216  
-		return $rs;
217  
-	}
  1
+<?php
  2
+
  3
+// security - hide paths
  4
+if (!defined('ADODB_DIR')) die();
  5
+
  6
+global $ADODB_INCLUDED_CSV;
  7
+$ADODB_INCLUDED_CSV = 1;
  8
+
  9
+/* 
  10
+  V4.50 6 July 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
  11
+  Released under both BSD license and Lesser GPL library license. 
  12
+  Whenever there is any discrepancy between the two licenses, 
  13
+  the BSD license will take precedence. See License.txt. 
  14
+  Set tabs to 4 for best viewing.
  15
+  
  16
+  Latest version is available at http://adodb.sourceforge.net
  17
+  
  18
+  Library for CSV serialization. This is used by the csv/proxy driver and is the 
  19
+  CacheExecute() serialization format. 
  20
+  
  21
+  ==== NOTE ====
  22
+  Format documented at http://php.weblogs.com/ADODB_CSV
  23
+  ==============
  24
+*/
  25
+
  26
+	/**
  27
+ 	 * convert a recordset into special format
  28
+	 *
  29
+	 * @param rs	the recordset
  30
+	 *
  31
+	 * @return	the CSV formated data
  32
+	 */
  33
+	function _rs2serialize(&$rs,$conn=false,$sql='')
  34
+	{
  35
+		$max = ($rs) ? $rs->FieldCount() : 0;
  36
+		
  37
+		if ($sql) $sql = urlencode($sql);
  38
+		// metadata setup
  39
+		
  40
+		if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
  41
+			if (is_object($conn)) {
  42
+				$sql .= ','.$conn->Affected_Rows();
  43
+				$sql .= ','.$conn->Insert_ID();
  44
+			} else
  45
+				$sql .= ',,';
  46
+			
  47
+			$text = "====-1,0,$sql\n";
  48
+			return $text;
  49
+		}
  50
+		$tt = ($rs->timeCreated) ? $rs->timeCreated : time();
  51
+		
  52
+		## changed format from ====0 to ====1
  53
+		$line = "====1,$tt,$sql\n";
  54
+		
  55
+		if ($rs->databaseType == 'array') {
  56
+			$rows =& $rs->_array;
  57
+		} else {
  58
+			$rows = array();
  59
+			while (!$rs->EOF) {	
  60
+				$rows[] = $rs->fields;
  61
+				$rs->MoveNext();
  62
+			} 
  63
+		}
  64
+		
  65
+		for($i=0; $i < $max; $i++) {
  66
+			$o =& $rs->FetchField($i);
  67
+			$flds[] = $o;
  68
+		}
  69
+		
  70
+		$rs =& new ADORecordSet_array();
  71
+		$rs->InitArrayFields($rows,$flds);
  72
+		return $line.serialize($rs);
  73
+	}
  74
+
  75
+	
  76
+/**
  77
+* Open CSV file and convert it into Data. 
  78
+*
  79
+* @param url  		file/ftp/http url
  80
+* @param err		returns the error message
  81
+* @param timeout	dispose if recordset has been alive for $timeout secs
  82
+*
  83
+* @return		recordset, or false if error occured. If no
  84
+*			error occurred in sql INSERT/UPDATE/DELETE, 
  85
+*			empty recordset is returned
  86
+*/
  87
+	function &csv2rs($url,&$err,$timeout=0)
  88
+	{
  89
+		$err = false;
  90
+		$fp = @fopen($url,'rb');
  91
+		if (!$fp) {
  92
+			$err = $url.' file/URL not found';
  93
+			return false;
  94
+		}
  95
+		flock($fp, LOCK_SH);
  96
+		$arr = array();
  97
+		$ttl = 0;
  98
+		
  99
+		if ($meta = fgetcsv($fp, 32000, ",")) {
  100
+			// check if error message
  101
+			if (strncmp($meta[0],'****',4) === 0) {
  102
+				$err = trim(substr($meta[0],4,1024));
  103
+				fclose($fp);
  104
+				return false;
  105
+			}
  106
+			// check for meta data
  107
+			// $meta[0] is -1 means return an empty recordset
  108
+			// $meta[1] contains a time 
  109
+	
  110
+			if (strncmp($meta[0], '====',4) === 0) {
  111
+			
  112
+				if ($meta[0] == "====-1") {
  113
+					if (sizeof($meta) < 5) {
  114
+						$err = "Corrupt first line for format -1";
  115
+						fclose($fp);
  116
+						return false;
  117
+					}
  118
+					fclose($fp);
  119
+					
  120
+					if ($timeout > 0) {
  121
+						$err = " Illegal Timeout $timeout ";
  122
+						return false;
  123
+					}
  124
+					$rs->fields = array();
  125
+					$rs->timeCreated = $meta[1];
  126
+					$rs =& new ADORecordSet($val=true);
  127
+					$rs->EOF = true;
  128
+					$rs->_numOfFields=0;
  129
+					$rs->sql = urldecode($meta[2]);
  130
+					$rs->affectedrows = (integer)$meta[3];
  131
+					$rs->insertid = $meta[4];	
  132
+					return $rs;
  133
+				} 
  134
+			# Under high volume loads, we want only 1 thread/process to _write_file
  135
+			# so that we don't have 50 processes queueing to write the same data.
  136
+			# We use probabilistic timeout, ahead of time.
  137
+			#
  138
+			# -4 sec before timeout, give processes 1/32 chance of timing out
  139
+			# -2 sec before timeout, give processes 1/16 chance of timing out
  140
+			# -1 sec after timeout give processes 1/4 chance of timing out
  141
+			# +0 sec after timeout, give processes 100% chance of timing out
  142
+				if (sizeof($meta) > 1) {
  143
+					if($timeout >0){ 
  144
+						$tdiff = (integer)( $meta[1]+$timeout - time());
  145
+						if ($tdiff <= 2) {
  146
+							switch($tdiff) {
  147
+							case 4:
  148
+							case 3:
  149
+								if ((rand() & 31) == 0) {
  150
+									fclose($fp);
  151
+									$err = "Timeout 3";
  152
+									return false;
  153
+								}
  154
+								break;
  155
+							case 2: 
  156
+								if ((rand() & 15) == 0) {
  157
+									fclose($fp);
  158
+									$err = "Timeout 2";
  159
+									return false;
  160
+								}
  161
+								break;
  162
+							case 1:
  163
+								if ((rand() & 3) == 0) {
  164
+									fclose($fp);
  165
+									$err = "Timeout 1";
  166
+									return false;
  167
+								}
  168
+								break;
  169
+							default: 
  170
+								fclose($fp);
  171
+								$err = "Timeout 0";
  172
+								return false;
  173
+							} // switch
  174
+							
  175
+						} // if check flush cache
  176
+					}// (timeout>0)
  177
+					$ttl = $meta[1];
  178
+				}
  179
+				//================================================
  180
+				// new cache format - use serialize extensively...
  181
+				if ($meta[0] === '====1') {
  182
+					// slurp in the data
  183
+					$MAXSIZE = 128000;
  184
+					
  185
+					$text = fread($fp,$MAXSIZE);
  186
+					if (strlen($text)) {
  187
+						while ($txt = fread($fp,$MAXSIZE)) {
  188
+							$text .= $txt;
  189
+						}
  190
+					}
  191
+					fclose($fp);
  192
+					$rs = unserialize($text);
  193
+					if (is_object($rs)) $rs->timeCreated = $ttl;
  194
+					else {
  195
+						$err = "Unable to unserialize recordset";
  196
+						//echo htmlspecialchars($text),' !--END--!<p>';
  197
+					}
  198
+					return $rs;
  199
+				}
  200
+				
  201
+				$meta = false;
  202
+				$meta = fgetcsv($fp, 32000, ",");
  203
+				if (!$meta) {
  204
+					fclose($fp);
  205
+					$err = "Unexpected EOF 1";
  206
+					return false;
  207
+				}
  208
+			}
  209
+
  210
+			// Get Column definitions
  211
+			$flds = array();
  212
+			foreach($meta as $o) {
  213
+				$o2 = explode(':',$o);
  214
+				if (sizeof($o2)!=3) {
  215
+					$arr[] = $meta;
  216
+					$flds = false;
  217
+					break;
  218
+				}
  219
+				$fld =& new ADOFieldObject();
  220
+				$fld->name = urldecode($o2[0]);
  221
+				$fld->type = $o2[1];
  222
+				$fld->max_length = $o2[2];
  223
+				$flds[] = $fld;
  224
+			}
  225
+		} else {
  226
+			fclose($fp);
  227
+			$err = "Recordset had unexpected EOF 2";
  228
+			return false;
  229
+		}
  230
+		
  231
+		// slurp in the data
  232
+		$MAXSIZE = 128000;
  233
+		
  234
+		$text = '';
  235
+		while ($txt = fread($fp,$MAXSIZE)) {
  236
+			$text .= $txt;
  237
+		}
  238
+			
  239
+		fclose($fp);
  240
+		@$arr = unserialize($text);
  241
+		//var_dump($arr);
  242
+		if (!is_array($arr)) {
  243
+			$err = "Recordset had unexpected EOF (in serialized recordset)";
  244
+			if (get_magic_quotes_runtime()) $err .= ". Magic Quotes Runtime should be disabled!";
  245
+			return false;
  246
+		}
  247
+		$rs =& new ADORecordSet_array();
  248
+		$rs->timeCreated = $ttl;
  249
+		$rs->InitArrayFields($arr,$flds);
  250
+		return $rs;
  251
+	}
218 252
 ?>
1,339  lib/adodb/adodb-datadict.inc.php
... ...
@@ -1,667 +1,674 @@
1  
-<?php
2  
-
3  
-/**
4  
-  V4.20 22 Feb 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
5  
-  Released under both BSD license and Lesser GPL library license. 
6  
-  Whenever there is any discrepancy between the two licenses, 
7  
-  the BSD license will take precedence.
8  
-	
9  
-  Set tabs to 4 for best viewing.
10  
- 
11  
- 	DOCUMENTATION:
12  
-	
13  
-		See adodb/tests/test-datadict.php for docs and examples.
14  
-*/
15  
-
16  
-/*
17  
-	Test script for parser
18  
-*/
19  
-function Lens_ParseTest()
20  
-{
21  
-$str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0";
22  
-print "<p>$str</p>";
23  
-$a= Lens_ParseArgs($str);
24  
-print "<pre>";
25  
-print_r($a);
26  
-print "</pre>";
27  
-}
28  
-
29  
-if (!function_exists('ctype_alnum')) {
30  
-	function ctype_alnum($text) {
31  
-		return preg_match('/^[a-z0-9]*$/i', $text);
32  
-	}
33  
-}
34  
-
35  
-//Lens_ParseTest();
36  
-
37  
-/**
38  
-	Parse arguments, treat "text" (text) and 'text' as quotation marks.
39  
-	To escape, use "" or '' or ))
40  
-	
41  
-	Will read in "abc def" sans quotes, as: abc def
42  
-	Same with 'abc def'.
43  
-	However if `abc def`, then will read in as `abc def`
44  
-	
45  
-	@param endstmtchar    Character that indicates end of statement
46  
-	@param tokenchars     Include the following characters in tokens apart from A-Z and 0-9 
47  
-	@returns 2 dimensional array containing parsed tokens.
48  
-*/
49  
-function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
50  
-{
51  
-	$pos = 0;
52  
-	$intoken = false;
53  
-	$stmtno = 0;
54  
-	$endquote = false;
55  
-	$tokens = array();
56  
-	$tokens[$stmtno] = array();
57  
-	$max = strlen($args);
58  
-	$quoted = false;
59  
-	
60  
-	while ($pos < $max) {
61  
-		$ch = substr($args,$pos,1);
62  
-		switch($ch) {
63  
-		case ' ':
64  
-		case "\t":
65  
-		case "\n":
66  
-		case "\r":
67  
-			if (!$quoted) {
68  
-				if ($intoken) {
69  
-					$intoken = false;
70  
-					$tokens[$stmtno][] = implode('',$tokarr);
71  
-				}
72  
-				break;
73  
-			}
74  
-			
75  
-			$tokarr[] = $ch;
76  
-			break;
77  
-		
78  
-		case '`':
79  
-			if ($intoken) $tokarr[] = $ch;
80  
-		case '(':
81  
-		case ')':	
82  
-		case '"':
83  
-		case "'":
84  
-			
85  
-			if ($intoken) {
86  
-				if (empty($endquote)) {
87  
-					$tokens[$stmtno][] = implode('',$tokarr);
88  
-					if ($ch == '(') $endquote = ')';
89  
-					else $endquote = $ch;
90  
-					$quoted = true;
91  
-					$intoken = true;
92  
-					$tokarr = array();
93  
-				} else if ($endquote == $ch) {
94  
-					$ch2 = substr($args,$pos+1,1);
95  
-					if ($ch2 == $endquote) {
96  
-						$pos += 1;
97  
-						$tokarr[] = $ch2;
98  
-					} else {
99  
-						$quoted = false;
100  
-						$intoken = false;
101  
-						$tokens[$stmtno][] = implode('',$tokarr);
102  
-						$endquote = '';
103  
-					}
104  
-				} else
105  
-					$tokarr[] = $ch;
106  
-					
107  
-			}else {
108  
-			
109  
-				if ($ch == '(') $endquote = ')';
110  
-				else $endquote = $ch;
111  
-				$quoted = true;
112  
-				$intoken = true;
113  
-				$tokarr = array();
114  
-				if ($ch == '`') $tokarr[] = '`';
115  
-			}
116  
-			break;
117  
-			
118  
-		default:
119  
-			
120  
-			if (!$intoken) {
121  
-				if ($ch == $endstmtchar) {
122  
-					$stmtno += 1;
123  
-					$tokens[$stmtno] = array();
124  
-					break;
125  
-				}
126  
-			
127  
-				$intoken = true;
128  
-				$quoted = false;
129  
-				$endquote = false;
130  
-				$tokarr = array();
131  
-	
132  
-			}
133  
-			
134  
-			if ($quoted) $tokarr[] = $ch;
135  
-			else if (ctype_alnum($ch) || strpos($tokenchars,$ch) !== false) $tokarr[] = $ch;
136  
-			else {
137  
-				if ($ch == $endstmtchar) {			
138  
-					$tokens[$stmtno][] = implode('',$tokarr);
139  
-					$stmtno += 1;
140  
-					$tokens[$stmtno] = array();
141  
-					$intoken = false;
142  
-					$tokarr = array();
143  
-					break;
144  
-				}
145  
-				$tokens[$stmtno][] = implode('',$tokarr);
146  
-				$tokens[$stmtno][] = $ch;
147  
-				$intoken = false;
148  
-			}
149  
-		}
150  
-		$pos += 1;
151  
-	}
152  
-	
153  
-	return $tokens;
154  
-}
155  
-
156  
-
157  
-class ADODB_DataDict {
158  
-	var $connection;
159  
-	var $debug = false;
160  
-	var $dropTable = 'DROP TABLE %s';
161  
-	var $dropIndex = 'DROP INDEX %s';
162  
-	var $addCol = ' ADD';
163  
-	var $alterCol = ' ALTER COLUMN';
164  
-	var $dropCol = ' DROP COLUMN';
165  
-	var $nameRegex = '\w';
166  
-	var $schema = false;
167  
-	var $serverInfo = array();
168  
-	var $autoIncrement = false;
169  
-	var $dataProvider;
170  
-	var $blobSize = 100; 	/// any varchar/char field this size or greater is treated as a blob
171  
-							/// in other words, we use a text area for editting.
172  
-	
173  
-	function GetCommentSQL($table,$col)
174  
-	{
175  
-		return false;
176  
-	}
177  
-	
178  
-	function SetCommentSQL($table,$col,$cmt)
179  
-	{
180  
-		return false;
181  
-	}
182  
-	
183  
-	function &MetaTables()
184  
-	{
185  
-		return $this->connection->MetaTables();
186  
-	}
187  
-	
188  
-	function &MetaColumns($tab, $upper=true, $schema=false)
189  
-	{
190  
-		return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema);
191  
-	}
192  
-	
193  
-	function &MetaPrimaryKeys($tab,$owner=false,$intkey=false)
194  
-	{
195  
-		return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey);
196  
-	}
197  
-	
198  
-	function &MetaIndexes($table, $primary = false, $owner = false)
199  
-	{
200  
-		return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner);
201  
-	}
202  
-	
203  
-	function MetaType($t,$len=-1,$fieldobj=false)
204  
-	{
205  
-		return ADORecordSet::MetaType($t,$len,$fieldobj);
206  
-	}
207  
-	
208  
-	function NameQuote($name = NULL)
209  
-	{
210  
-		if (!is_string($name)) {
211  
-			return FALSE;
212  
-		}
213  
-		
214  
-		$name = trim($name);
215  
-		
216  
-		if ( !is_object($this->connection) ) {
217  
-			return $name;
218  
-		}
219  
-		
220  
-		$quote = $this->connection->nameQuote;
221  
-		
222  
-		// if name is of the form `name`, quote it
223  
-		if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
224  
-			return $quote . $matches[1] . $quote;
225  
-		}
226  
-		
227  
-		// if name contains special characters, quote it
228  
-		if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
229  
-			return $quote . $name . $quote;
230  
-		}
231  
-		
232  
-		return $name;
233  
-	}
234  
-	
235  
-	function TableName($name)
236  
-	{
237  
-		if ( $this->schema ) {
238  
-			return $this->NameQuote($this->schema) .'.'. $this->NameQuote($name);
239  
-		}
240  
-		return $this->NameQuote($name);
241  
-	}
242  
-	
243  
-	// Executes the sql array returned by GetTableSQL and GetIndexSQL
244  
-	function ExecuteSQLArray($sql, $continueOnError = true)
245  
-	{
246  
-		$rez = 2;
247  
-		$conn = &$this->connection;
248  
-		$saved = $conn->debug;
249  
-		foreach($sql as $line) {
250  
-			
251  
-			if ($this->debug) $conn->debug = true;
252  
-			$ok = $conn->Execute($line);
253  
-			$conn->debug = $saved;
254  
-			if (!$ok) {
255  
-				if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
256  
-				if (!$continueOnError) return 0;
257  
-				$rez = 1;
258  
-			}
259  
-		}
260  
-		return 2;
261  
-	}
262  
-	
263  
-	/*
264  
-	 	Returns the actual type given a character code.
265  
-		
266  
-		C:  varchar
267  
-		X:  CLOB (character large object) or largest varchar size if CLOB is not supported
268  
-		C2: Multibyte varchar
269  
-		X2: Multibyte CLOB
270  
-		
271  
-		B:  BLOB (binary large object)
272  
-		
273  
-		D:  Date
274  
-		T:  Date-time 
275  
-		L:  Integer field suitable for storing booleans (0 or 1)
276  
-		I:  Integer
277  
-		F:  Floating point number
278  
-		N:  Numeric or decimal number
279  
-	*/
280  
-	
281  
-	function ActualType($meta)
282  
-	{
283  
-		return $meta;
284  
-	}
285  
-	
286  
-	function CreateDatabase($dbname,$options=false)
287  
-	{
288  
-		$options = $this->_Options($options);
289  
-		$sql = array();
290  
-		
291  
-		$s = 'CREATE DATABASE ' . $this->NameQuote($dbname);
292  
-		if (isset($options[$this->upperName]))
293  
-			$s .= ' '.$options[$this->upperName];
294  
-		
295  
-		$sql[] = $s;
296  
-		return $sql;
297  
-	}
298  
-	
299  
-	/*
300  
-	 Generates the SQL to create index. Returns an array of sql strings.
301  
-	*/
302  
-	function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false)
303  
-	{
304  
-		if (!is_array($flds)) {
305  
-			$flds = explode(',',$flds);
306  
-		}
307  
-		
308  
-		foreach($flds as $key => $fld) {
309  
-			$flds[$key] = $this->NameQuote($fld);
310  
-		}
311  
-		
312  
-		return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions));
313  
-	}
314  
-	
315  
-	function DropIndexSQL ($idxname, $tabname = NULL)
316  
-	{
317  
-		return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname)));
318  
-	}
319  
-	
320  
-	function SetSchema($schema)
321  
-	{
322  
-		$this->schema = $schema;
323  
-	}
324  
-	
325  
-	function AddColumnSQL($tabname, $flds)
326  
-	{
327  
-		$tabname = $this->TableName ($tabname);
328  
-		$sql = array();
329  
-		list($lines,$pkey) = $this->_GenFields($flds);
330  
-		$alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' ';
331  
-		foreach($lines as $v) {
332  
-			$sql[] = $alter . $v;
333  
-		}
334  
-		return $sql;
335  
-	}
336  
-	
337  
-	function AlterColumnSQL($tabname, $flds)
338  
-	{
339  
-		$tabname = $this->TableName ($tabname);
340  
-		$sql = array();
341  
-		list($lines,$pkey) = $this->_GenFields($flds);
342  
-		$alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
343  
-		foreach($lines as $v) {
344  
-			$sql[] = $alter . $v;
345  
-		}
346  
-		return $sql;
347  
-	}
348  
-	
349  
-	function DropColumnSQL($tabname, $flds)
350  
-	{
351  
-		$tabname = $this->TableName ($tabname);
352  
-		if (!is_array($flds)) $flds = explode(',',$flds);
353  
-		$sql = array();
354  
-		$alter = 'ALTER TABLE ' . $tabname . $this->dropCol . ' ';
355  
-		foreach($flds as $v) {
356  
-			$sql[] = $alter . $this->NameQuote($v);
357  
-		}
358  
-		return $sql;
359  
-	}
360  
-	
361  
-	function DropTableSQL($tabname)
362  
-	{
363  
-		return array (sprintf($this->dropTable, $this->TableName($tabname)));
364  
-	}
365  
-	
366  
-	/*
367  
-	 Generate the SQL to create table. Returns an array of sql strings.
368  
-	*/
369  
-	function CreateTableSQL($tabname, $flds, $tableoptions=false)
370  
-	{
371  
-		if (!$tableoptions) $tableoptions = array();
372  
-		
373  
-		list($lines,$pkey) = $this->_GenFields($flds);
374  
-		
375  
-		$taboptions = $this->_Options($tableoptions);
376  
-		$tabname = $this->TableName ($tabname);
377  
-		$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
378  
-		
379  
-		$tsql = $this->_Triggers($tabname,$taboptions);
380  
-		foreach($tsql as $s) $sql[] = $s;
381  
-		
382  
-		return $sql;
383  
-	}
384  
-	
385  
-	function _GenFields($flds)
386  
-	{
387  
-		if (is_string($flds)) {
388  
-			$padding = '     ';
389  
-			$txt = $flds.$padding;
390  
-			$flds = array();
391  
-			$flds0 = Lens_ParseArgs($txt,',');
392  
-			$hasparam = false;
393  
-			foreach($flds0 as $f0) {
394  
-				$f1 = array();
395  
-				foreach($f0 as $token) {
396  
-					switch (strtoupper($token)) {
397  
-					case 'CONSTRAINT':
398  
-					case 'DEFAULT': 
399  
-						$hasparam = $token;
400  
-						break;
401  
-					default:
402  
-						if ($hasparam) $f1[$hasparam] = $token;
403  
-						else $f1[] = $token;
404  
-						$hasparam = false;
405  
-						break;
406  
-					}
407  
-				}
408  
-				$flds[] = $f1;
409  
-				
410  
-			}
411  
-		}
412  
-		$this->autoIncrement = false;
413  
-		$lines = array();
414  
-		$pkey = array();
415  
-		foreach($flds as $fld) {
416  
-			$fld = _array_change_key_case($fld);
417  
-		
418  
-			$fname = false;
419  
-			$fdefault = false;
420  
-			$fautoinc = false;
421  
-			$ftype = false;
422  
-			$fsize = false;
423  
-			$fprec = false;
424  
-			$fprimary = false;
425  
-			$fnoquote = false;
426  
-			$fdefts = false;
427  
-			$fdefdate = false;
428  
-			$fconstraint = false;
429  
-			$fnotnull = false;
430  
-			$funsigned = false;
431  
-			
432  
-			//-----------------
433  
-			// Parse attributes
434  
-			foreach($fld as $attr => $v) {
435  
-				if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';
436  
-				else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);
437  
-				
438  
-				switch($attr) {
439  
-				case '0':
440  
-				case 'NAME': 	$fname = $v; break;
441  
-				case '1':
442  
-				case 'TYPE': 	$ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
443  
-				
444  
-				case 'SIZE': 	
445  
-								$dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
446  
-								if ($dotat === false) $fsize = $v;
447  
-								else {
448  
-									$fsize = substr($v,0,$dotat);
449  
-									$fprec = substr($v,$dotat+1);
450  
-								}
451  
-								break;
452  
-				case 'UNSIGNED': $funsigned = true; break;
453  
-				case 'AUTOINCREMENT':
454  
-				case 'AUTO':	$fautoinc = true; $fnotnull = true; break;
455  
-				case 'KEY':
456  
-				case 'PRIMARY':	$fprimary = $v; $fnotnull = true; break;
457  
-				case 'DEF':
458  
-				case 'DEFAULT': $fdefault = $v; break;
459  
-				case 'NOTNULL': $fnotnull = $v; break;
460  
-				case 'NOQUOTE': $fnoquote = $v; break;
461  
-				case 'DEFDATE': $fdefdate = $v; break;
462  
-				case 'DEFTIMESTAMP': $fdefts = $v; break;
463  
-				case 'CONSTRAINT': $fconstraint = $v; break;
464  
-				} //switch
465  
-			} // foreach $fld
466  
-			
467  
-			//--------------------
468  
-			// VALIDATE FIELD INFO
469  
-			if (!strlen($fname)) {
470  
-				if ($this->debug) ADOConnection::outp("Undefined NAME");
471  
-				return false;
472  
-			}
473  
-			
474  
-			$fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname));
475  
-			$fname = $this->NameQuote($fname);
476  
-			
477  
-			if (!strlen($ftype)) {
478  
-				if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
479  
-				return false;
480  
-			} else {
481  
-				$ftype = strtoupper($ftype);
482  
-			}
483  
-			
484  
-			$ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
485  
-			
486  
-			if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls
487  
-			
488  
-			if ($fprimary) $pkey[] = $fname;
489  
-			
490  
-			// some databases do not allow blobs to have defaults
491  
-			if ($ty == 'X') $fdefault = false;
492  
-			
493  
-			//--------------------
494  
-			// CONSTRUCT FIELD SQL
495  
-			if ($fdefts) {
496  
-				if (substr($this->connection->databaseType,0,5) == 'mysql') {
497  
-					$ftype = 'TIMESTAMP';
498  
-				} else {
499  
-					$fdefault = $this->connection->sysTimeStamp;
500  
-				}
501  
-			} else if ($fdefdate) {
502  
-				if (substr($this->connection->databaseType,0,5) == 'mysql') {
503  
-					$ftype = 'TIMESTAMP';
504  
-				} else {
505  
-					$fdefault = $this->connection->sysDate;
506  
-				}
507  
-			} else if (strlen($fdefault) && !$fnoquote)
508  
-				if ($ty == 'C' or $ty == 'X' or 
509  
-					( substr($fdefault,0,1) != "'" && !is_numeric($fdefault)))
510  
-					if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ') 
511  
-						$fdefault = trim($fdefault);
512  
-					else if (strtolower($fdefault) != 'null')
513  
-						$fdefault = $this->connection->qstr($fdefault);
514  
-			$suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned);
515  
-			
516  
-			$fname = str_pad($fname,16);
517  
-			$lines[$fid] = $fname.' '.$ftype.$suffix;
518  
-			
519  
-			if ($fautoinc) $this->autoIncrement = true;
520  
-		} // foreach $flds
521  
-		
522  
-		return array($lines,$pkey);
523  
-	}
524  
-	/*
525  
-		 GENERATE THE SIZE PART OF THE DATATYPE
526  
-			$ftype is the actual type
527  
-			$ty is the type defined originally in the DDL
528  
-	*/
529  
-	function _GetSize($ftype, $ty, $fsize, $fprec)
530  
-	{
531  
-		if (strlen($fsize) && $ty != 'X' && $ty != 'B' && strpos($ftype,'(') === false) {
532  
-			$ftype .= "(".$fsize;
533  
-			if (strlen($fprec)) $ftype .= ",".$fprec;
534  
-			$ftype .= ')';
535  
-		}
536  
-		return $ftype;
537  
-	}
538  
-	
539  
-	
540  
-	// return string must begin with space
541  
-	function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
542  
-	{	
543  
-		$suffix = '';
544  
-		if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
545  
-		if ($fnotnull) $suffix .= ' NOT NULL';
546  
-		if ($fconstraint) $suffix .= ' '.$fconstraint;
547  
-		return $suffix;
548  
-	}
549  
-	
550  
-	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
551  
-	{
552  
-		$sql = array();
553  
-		
554  
-		if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
555  
-			$sql[] = sprintf ($this->dropIndex, $idxname);
556  
-			if ( isset($idxoptions['DROP']) )
557  
-				return $sql;
558  
-		}
559  
-		
560  
-		if ( empty ($flds) ) {
561  
-			return $sql;
562  
-		}
563  
-		
564  
-		$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
565  
-	
566  
-		$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
567  
-		
568  
-		if ( isset($idxoptions[$this->upperName]) )
569  
-			$s .= $idxoptions[$this->upperName];
570  
-		
571  
-		if ( is_array($flds) )
572  
-			$flds = implode(', ',$flds);
573  
-		$s .= '(' . $flds . ')';
574  
-		$sql[] = $s;
575  
-		
576  
-		return $sql;
577  
-	}
578  
-	
579  
-	function _DropAutoIncrement($tabname)
580  
-	{
581  
-		return false;
582  
-	}
583  
-	
584  
-	function _TableSQL($tabname,$lines,$pkey,$tableoptions)
585  
-	{
586  
-		$sql = array();
587  
-		
588  
-		if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
589  
-			$sql[] = sprintf($this->dropTable,$tabname);
590  
-			if ($this->autoIncrement) {
591  
-				$sInc = $this->_DropAutoIncrement($tabname);
592  
-				if ($sInc) $sql[] = $sInc;
593  
-			}
594  
-			if ( isset ($tableoptions['DROP']) ) {
595  
-				return $sql;
596  
-			}
597  
-		}
598  
-		$s = "CREATE TABLE $tabname (\n";
599  
-		$s .= implode(",\n", $lines);
600  
-		if (sizeof($pkey)>0) {
601  
-			$s .= ",\n                 PRIMARY KEY (";
602  
-			$s .= implode(", ",$pkey).")";
603  
-		}
604  
-		if (isset($tableoptions['CONSTRAINTS'])) 
605  
-			$s .= "\n".$tableoptions['CONSTRAINTS'];
606  
-		
607  
-		if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) 
608  
-			$s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
609  
-		
610  
-		$s .= "\n)";
611  
-		if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
612  
-		$sql[] = $s;
613  
-		
614  
-		return $sql;
615  
-	}
616  
-	
617  
-	/*
618  
-		GENERATE TRIGGERS IF NEEDED
619  
-		used when table has auto-incrementing field that is emulated using triggers
620  
-	*/
621  
-	function _Triggers($tabname,$taboptions)
622  
-	{
623  
-		return array();
624  
-	}
625  
-	
626  
-	/*
627  
-		Sanitize options, so that array elements with no keys are promoted to keys
628  
-	*/
629  
-	function _Options($opts)
630  
-	{
631  
-		if (!is_array($opts)) return array();
632  
-		$newopts = array();
633  
-		foreach($opts as $k => $v) {
634  
-			if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
635  
-			else $newopts[strtoupper($k)] = $v;
636  
-		}
637  
-		return $newopts;
638  
-	}
639  
-	
640  
-	/*
641  
-	"Florian Buzin [ easywe ]" <florian.buzin@easywe.de>
642  
-	
643  
-	This function changes/adds new fields to your table. You don't
644  
-	have to know if the col is new or not. It will check on its own.
645  
-	*/
646  
-	function ChangeTableSQL($tablename, $flds, $tableoptions = false)
647  
-	{
648  
-		if ( !is_array($cols = &$this->MetaColumns($tablename)) ) {
649  
-			return $this->CreateTableSQL($tablename, $flds, $tableoptions);
650  
-		}
651  
-		
652  
-		list($lines,$pkey) = $this->_GenFields($flds);
653  
-		$alter = 'ALTER TABLE ' . $this->TableName($tablename);
654  
-		$sql = array();
655  
-		
656  
-		foreach ( $lines as $id => $v ) {
657  
-			if ( isset($cols[$id]) && is_object($cols[$id]) ) {
658  
-				$sql[] = $alter . $this->alterCol . ' ' . $v;
659  
-			} else {
660  
-				$sql[] = $alter . $this->addCol . ' ' . $v;
661  
-			}