source: trunk/client/class/db/sqlite.php@ 394

Last change on this file since 394 was 232, checked in by luc, 9 years ago
  • inclusione del tema per mobile Futura2 - inclusione del widget per la ricerca dei candidati - inclusione della segnalazione dell'installazione - altre piccole migliorie.

Inserita classe e file mancanti

File size: 5.6 KB
Line 
1<?php
2/***************************************************************************
3 * sqlite.php
4 * -------------------
5 * begin : Saturday, Feb 13, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
8 *
9 * $Id: sqlite.php,v 1.16 2002/03/19 01:07:36 psotfx Exp $
10 *
11 ***************************************************************************/
12
13/***************************************************************************
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 ***************************************************************************/
21
22if(!defined('SQL_LAYER'))
23{
24
25define('SQL_LAYER', 'sqlite');
26
27class sql_db
28{
29
30 var $db_connect_id;
31 var $query_result;
32 var $row = array();
33 var $rowset = array();
34 var $num_queries = 0;
35
36 //
37 // Constructor
38 //
39 function sql_db($sqlserver, $trash, $trash, $trash, $persistency = true)
40 {
41 $this->persistency = $persistency;
42 $this->server = $sqlserver;
43
44 $this->db_connect_id = ($this->persistency) ? @sqlite_popen($this->server, 0666, $sqliteerror) : @sqlite_open($this->server, 0666, $sqliteerror);
45
46 return ($this->db_connect_id) ? $this->db_connect_id : false;
47 }
48
49 //
50 // Other base methods
51 //
52 function sql_close()
53 {
54 return ($this->db_connect_id) ? @sqlite_close($this->db_connect_id) : false;
55 }
56
57 //
58 // Base query method
59 //
60 function sql_query($query = '', $transaction = FALSE)
61 {
62 // Remove any pre-existing queries
63 unset($this->query_result);
64
65 if($query != '')
66 {
67 $this->num_queries++;
68
69 $this->query_result = @sqlite_query($query, $this->db_connect_id);
70 }
71
72 if($this->query_result)
73 {
74 unset($this->row[$this->query_result]);
75 unset($this->rowset[$this->query_result]);
76
77 return $this->query_result;
78 }
79 else
80 {
81 return ( $transaction == END_TRANSACTION ) ? true : false;
82 }
83 }
84
85 //
86 // Other query methods
87 //
88 function sql_numrows($query_id = 0)
89 {
90 if(!$query_id)
91 {
92 $query_id = $this->query_result;
93 }
94
95 if($query_id)
96 {
97 return @sqlite_num_rows($query_id);
98 }
99 else
100 {
101 return false;
102 }
103 }
104
105 function sql_affectedrows()
106 {
107 return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false;
108 }
109
110 function sql_numfields($query_id = 0)
111 {
112 if(!$query_id)
113 {
114 $query_id = $this->query_result;
115 }
116
117 return ($query_id) ? @sqlite_num_fields($query_id) : false;
118 }
119
120 function sql_fieldname($offset, $query_id = 0)
121 {
122 if(!$query_id)
123 {
124 $query_id = $this->query_result;
125 }
126
127 return ($query_id) ? @sqlite_field_name($query_id, $offset) : false;
128 }
129
130 function sql_fieldtype($offset, $query_id = 0)
131 {
132 exit('sql_fieldtype called');
133
134 if(!$query_id)
135 {
136 $query_id = $this->query_result;
137 }
138
139 // return ($query_id) ? @mysql_field_type($query_id, $offset) : false;
140 return ($query_id) ? 'varchar' : false;
141 }
142
143 function sql_fetchrow($query_id = 0)
144 {
145 if(!$query_id)
146 {
147 $query_id = $this->query_result;
148 }
149
150 if($query_id)
151 {
152 //$this->row[$query_id] = @sqlite_fetch_array($query_id);
153 //return $this->row[$query_id];
154
155
156 $result = sqlite_fetch_array($query_id);
157
158 if ($result)
159 {
160 foreach ($result as $key => $value)
161 {
162 if ($pos = strpos($key, '.'))
163 {
164 $key = substr($key, $pos+1);
165 }
166
167 $array[$key] = $value;
168 }
169 }
170
171 $this->row[$query_id] = $array;
172
173 return $this->row[$query_id];
174 }
175 else
176 {
177 return false;
178 }
179 }
180
181 function sql_fetchrowset($query_id = 0)
182 {
183 if(!$query_id)
184 {
185 $query_id = $this->query_result;
186 }
187
188 if($query_id)
189 {
190 unset(
191 $this->rowset[$query_id],
192 $this->row[$query_id]
193 );
194
195 while($this->rowset[$query_id] = @sqlite_fetch_array($query_id))
196 {
197 foreach ($this->rowset[$query_id] as $key => $value)
198 {
199 if ($pos = strpos($key, '.'))
200 {
201 $key = substr($key, $pos+1);
202 }
203
204 $array[$key] = $value;
205 }
206
207 $result[] = $array;
208 }
209
210 return $result;
211 }
212 else
213 {
214 return false;
215 }
216 }
217
218 function sql_fetchfield($field, $rownum = -1, $query_id = 0)
219 {
220 exit('sql_fetchfield called');
221
222 if( !$query_id )
223 {
224 $query_id = $this->query_result;
225 }
226
227 if( $query_id )
228 {
229 if( $rownum > -1 )
230 {
231 $result = mysql_result($query_id, $rownum, $field);
232 }
233 else
234 {
235 if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) )
236 {
237 if( $this->sql_fetchrow() )
238 {
239 $result = $this->row[$query_id][$field];
240 }
241 }
242 else
243 {
244 if( $this->rowset[$query_id] )
245 {
246 $result = $this->rowset[$query_id][$field];
247 }
248 else if( $this->row[$query_id] )
249 {
250 $result = $this->row[$query_id][$field];
251 }
252 }
253 }
254
255 return $result;
256 }
257 else
258 {
259 return false;
260 }
261 }
262
263 function sql_rowseek($rownum, $query_id = 0)
264 {
265 if(!$query_id)
266 {
267 $query_id = $this->query_result;
268 }
269
270 return ($query_id) ? @sqlite_seek($query_id, $rownum) : false;
271 }
272
273 function sql_nextid()
274 {
275 return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false;
276 }
277
278 function sql_freeresult($query_id = 0)
279 {
280 if(!$query_id)
281 {
282 $query_id = $this->query_result;
283 }
284
285 if ( $query_id )
286 {
287 unset(
288 $this->row[$query_id],
289 $this->rowset[$query_id]
290 );
291
292 //@mysql_free_result($query_id);
293
294 return true;
295 }
296 else
297 {
298 return false;
299 }
300 }
301
302 function sql_error()
303 {
304 $result['code'] = sqlite_last_error($this->db_connect_id);
305 $result['message'] = sqlite_error_string($result['code']);
306
307 return $result;
308 }
309
310} // class sql_db
311
312} // if ... define
313
314?>
Note: See TracBrowser for help on using the repository browser.