RSS

(root)/phpwe/sWG_basic : 2 : system/classes/swg_db.php

« back to all changes in this revision

Viewing changes to system/classes/swg_db.php

@4u
2009-06-17 10:25:56
Revision ID: @4u-20090617102556-9i7k61py79uu57lc
Initial commit
Trivial: We are working with Bazaar not CVS

Show diffs side-by-side

added added

removed removed

 
1
<?php
 
2
//j// BOF
 
3
 
 
4
/*n// NOTE
 
5
----------------------------------------------------------------------------
 
6
secured WebGine
 
7
net-based application engine
 
8
----------------------------------------------------------------------------
 
9
(C) direct Netware Group - All rights reserved
 
10
http://www.direct-netware.de/redirect.php?swg
 
11
 
 
12
This work is distributed under the W3C (R) Software License, but without any
 
13
warranty; without even the implied warranty of merchantability or fitness
 
14
for a particular purpose.
 
15
----------------------------------------------------------------------------
 
16
http://www.direct-netware.de/redirect.php?licenses;w3c
 
17
----------------------------------------------------------------------------
 
18
$Id: swg_db.php,v 1.7 2008/12/20 11:23:19 s4u Exp $
 
19
#echo(sWGbasicVersion)#
 
20
sWG/#echo(__FILEPATH__)#
 
21
----------------------------------------------------------------------------
 
22
NOTE_END //n*/
 
23
/**
 
24
* We need a unified interface for communication with SQL-compatible database
 
25
* servers. This is the abstract interface.
 
26
*
 
27
* @internal   We are using phpDocumentor to automate the documentation process
 
28
*             for creating the Developer's Manual. All sections including
 
29
*             these special comments will be removed from the release source
 
30
*             code.
 
31
*             Use the following line to ensure 76 character sizes:
 
32
* ----------------------------------------------------------------------------
 
33
* @author     direct Netware Group
 
34
* @copyright  (C) direct Netware Group - All rights reserved
 
35
* @package    sWG_basic
 
36
* @subpackage db
 
37
* @since      v0.1.00
 
38
* @license    http://www.direct-netware.de/redirect.php?licenses;w3c
 
39
*             W3C (R) Software License
 
40
*/
 
41
 
 
42
/* -------------------------------------------------------------------------
 
43
All comments will be removed in the "production" packages (they will be in
 
44
all development packets)
 
45
------------------------------------------------------------------------- */
 
46
 
 
47
//j// Functions and classes
 
48
 
 
49
/* -------------------------------------------------------------------------
 
50
Testing for required classes
 
51
------------------------------------------------------------------------- */
 
52
 
 
53
$g_continue_check = true;
 
54
if (defined ("CLASS_direct_db")) { $g_continue_check = false; }
 
55
if (!defined ("CLASS_direct_data_handler")) { $g_continue_check = false; }
 
56
 
 
57
if ($g_continue_check)
 
58
{
 
59
//c// direct_db
 
60
/**
 
61
* This is the abstract interface to communicate with SQL servers.
 
62
*
 
63
* @author     direct Netware Group
 
64
* @copyright  (C) direct Netware Group - All rights reserved
 
65
* @package    sWG_basic
 
66
* @subpackage db
 
67
* @uses       CLASS_direct_data_handler
 
68
* @since      v0.1.00
 
69
* @license    http://www.direct-netware.de/redirect.php?licenses;w3c
 
70
*             W3C (R) Software License
 
71
*/
 
72
class direct_db extends direct_data_handler
 
73
{
 
74
/**
 
75
        * @var resource $db_driver Database layer
 
76
*/
 
77
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $db_driver;
 
78
/**
 
79
        * @var string $db_driver_name Database layer name
 
80
*/
 
81
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $db_driver_name;
 
82
/**
 
83
        * @var array $query_attributes SQL query attributes
 
84
*/
 
85
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_attributes;
 
86
/**
 
87
        * @var integer $query_element Counter for the element tags
 
88
*/
 
89
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_element;
 
90
/**
 
91
        * @var array $query_grouping SQL query GROUP BY
 
92
*/
 
93
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_grouping;
 
94
/**
 
95
        * @var array $query_joins SQL query JOIN
 
96
*/
 
97
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_joins;
 
98
/**
 
99
        * @var array $query_limit SQL query LIMIT
 
100
*/
 
101
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_limit;
 
102
/**
 
103
        * @var array $query_offset SQL query OFFSET
 
104
*/
 
105
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_offset;
 
106
/**
 
107
        * @var array $query_ordering SQL query ORDER BY
 
108
*/
 
109
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_ordering;
 
110
/**
 
111
        * @var array $query_row_conditions SQL query WHERE
 
112
*/
 
113
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_row_conditions;
 
114
/**
 
115
        * @var array $query_search_conditions SQL query search conditions
 
116
*/
 
117
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_search_conditions;
 
118
/**
 
119
        * @var array $query_set_attributes SQL query SET
 
120
*/
 
121
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_set_attributes;
 
122
/**
 
123
        * @var array $query_table SQL query FROM
 
124
*/
 
125
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_table;
 
126
/**
 
127
        * @var array $query_type SQL query type
 
128
*/
 
129
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_type;
 
130
/**
 
131
        * @var array $query_values SQL query VALUES
 
132
*/
 
133
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_values;
 
134
/**
 
135
        * @var array $query_values_keys SQL query KEYS
 
136
*/
 
137
        /*#ifndef(PHP4) */protected/* #*//*#ifdef(PHP4):var:#*/ $query_values_keys;
 
138
 
 
139
/* -------------------------------------------------------------------------
 
140
Extend the class using old and new behavior
 
141
------------------------------------------------------------------------- */
 
142
 
 
143
        //f// direct_db->__construct () and direct_db->direct_db ()
 
144
/**
 
145
        * Constructor (PHP5) __construct (direct_db)
 
146
        *
 
147
        * @param boolean $f_peristent True to establish a persistent connection
 
148
        * @uses  direct_basic_functions::include_file()
 
149
        * @uses  direct_basic_functions::settings_get()
 
150
        * @uses  direct_class_init()
 
151
        * @uses  direct_debug()
 
152
        * @uses  USE_debug_reporting
 
153
        * @since v0.1.00
 
154
*/
 
155
        /*#ifndef(PHP4) */public /* #*/function __construct ($f_peristent = false)
 
156
        {
 
157
                global $direct_cachedata,$direct_classes,$direct_settings;
 
158
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->__construct (direct_db)- (#echo(__LINE__)#)"); }
 
159
 
 
160
/* -------------------------------------------------------------------------
 
161
My parent should be on my side to get the work done
 
162
------------------------------------------------------------------------- */
 
163
 
 
164
                parent::__construct ();
 
165
 
 
166
/* -------------------------------------------------------------------------
 
167
Informing the system about available functions 
 
168
------------------------------------------------------------------------- */
 
169
 
 
170
                $this->functions['define_attributes'] = true;
 
171
                $this->functions['define_grouping'] = true;
 
172
                $this->functions['define_join'] = true;
 
173
                $this->functions['define_limit'] = true;
 
174
                $this->functions['define_offset'] = true;
 
175
                $this->functions['define_ordering'] = true;
 
176
                $this->functions['define_row_conditions'] = true;
 
177
                $this->functions['define_row_conditions_encode'] = false;
 
178
                $this->functions['define_search_conditions'] = true;
 
179
                $this->functions['define_set_attributes'] = true;
 
180
                $this->functions['define_set_attributes_encode'] = false;
 
181
                $this->functions['define_values'] = true;
 
182
                $this->functions['define_values_encode'] = false;
 
183
                $this->functions['define_values_keys'] = true;
 
184
                $this->functions['init_delete'] = false;
 
185
                $this->functions['init_insert'] = false;
 
186
                $this->functions['init_replace'] = false;
 
187
                $this->functions['init_select'] = false;
 
188
                $this->functions['init_update'] = false;
 
189
                $this->functions['optimize_random'] = false;
 
190
                $this->functions['query_exec'] = false;
 
191
                $this->functions['v_close'] = array ();
 
192
                $this->functions['v_connect'] = array ();
 
193
                $this->functions['v_optimize'] = array ();
 
194
                $this->functions['v_query_build'] = array ();
 
195
                $this->functions['v_query_exec'] = array ();
 
196
                $this->functions['v_secure'] = array ();
 
197
                $this->functions['v_transaction_begin'] = array ();
 
198
                $this->functions['v_transaction_commit'] = array ();
 
199
                $this->functions['v_transaction_rollback'] = array ();
 
200
 
 
201
                if (file_exists ($direct_settings['path_data']."/settings/swg_db.php"))
 
202
                {
 
203
                        $direct_classes['basic_functions']->settings_get ($direct_settings['path_data']."/settings/swg_db.php");
 
204
 
 
205
                        if (isset ($direct_settings['db_driver'])) { $this->db_driver_name = $direct_settings['db_driver']; }
 
206
                        else { $this->db_driver_name = "mysql"; }
 
207
 
 
208
                        if (!isset ($direct_settings['db_dbprefix'])) { $direct_settings['db_dbprefix'] = "swg_"; }
 
209
 
 
210
                        if ($f_peristent) { $direct_settings['db_peristent'] = true; }
 
211
                        elseif (!isset ($direct_settings['db_peristent'])) { $direct_settings['db_peristent'] = $f_peristent; }
 
212
                        else { $direct_settings['db_peristent'] = false; }
 
213
 
 
214
                        if ($direct_classes['basic_functions']->include_file ($direct_settings['path_system']."/classes/swg_dbraw_".$this->db_driver_name.".php",1))
 
215
                        {
 
216
                                $f_dbraw_class = "direct_dbraw_".$this->db_driver_name;
 
217
                                if (class_exists ($f_dbraw_class,/*#ifndef(PHP4) */false/* #*/)) { $this->db_driver = new $f_dbraw_class (); }
 
218
 
 
219
                                if (is_object ($this->db_driver))
 
220
                                {
 
221
                                        $this->functions['define_row_conditions_encode'] = true;
 
222
                                        $this->functions['define_set_attributes_encode'] = true;
 
223
                                        $this->functions['define_values_encode'] = true;
 
224
                                        $this->functions['init_delete'] = true;
 
225
                                        $this->functions['init_insert'] = true;
 
226
                                        $this->functions['init_replace'] = true;
 
227
                                        $this->functions['init_select'] = true;
 
228
                                        $this->functions['init_update'] = true;
 
229
                                        $this->functions['optimize_random'] = true;
 
230
                                        $this->functions['query_exec'] = true;
 
231
 
 
232
/* -------------------------------------------------------------------------
 
233
Connect to the database abstraction layer
 
234
------------------------------------------------------------------------- */
 
235
 
 
236
                                        $this->v_call_set ("v_connect",$this->db_driver,"connect");
 
237
                                        $this->v_call_set ("v_disconnect",$this->db_driver,"disconnect");
 
238
                                        $this->v_call_set ("v_optimize",$this->db_driver,"optimize");
 
239
                                        $this->v_call_set ("v_query_build",$this->db_driver,"query_build");
 
240
                                        $this->v_call_set ("v_query_exec",$this->db_driver,"query_exec");
 
241
                                        $this->v_call_set ("v_secure",$this->db_driver,"secure");
 
242
                                        $this->v_call_set ("v_transaction_begin",$this->db_driver,"transaction_begin");
 
243
                                        $this->v_call_set ("v_transaction_commit",$this->db_driver,"transaction_commit");
 
244
                                        $this->v_call_set ("v_transaction_rollback",$this->db_driver,"transaction_rollback");
 
245
                                }
 
246
                        }
 
247
                        else { trigger_error ("sWG/#echo(__FILEPATH__)# -db_class->__construct (direct_db)- (#echo(__LINE__)#) reporting: Fatal error while loading the raw SQL handler",E_USER_ERROR); }
 
248
                }
 
249
                else { trigger_error ("sWG/#echo(__FILEPATH__)# -db_class->__construct (direct_db)- (#echo(__LINE__)#) reporting: Fatal error while loading database settings",E_USER_ERROR); }
 
250
 
 
251
/* -------------------------------------------------------------------------
 
252
Set up some variables
 
253
------------------------------------------------------------------------- */
 
254
 
 
255
                $this->query_attributes = "";
 
256
                $this->query_element = 0;
 
257
                $this->query_grouping = "";
 
258
                $this->query_joins = array ();
 
259
                $this->query_limit = 0;
 
260
                $this->query_offset = 0;
 
261
                $this->query_ordering = "";
 
262
                $this->query_row_conditions = "";
 
263
                $this->query_search_conditions = array ();
 
264
                $this->query_set_attributes = array ();
 
265
                $this->query_table = "";
 
266
                $this->query_type = "";
 
267
                $this->query_values = "";
 
268
                $this->query_values_keys = array ();
 
269
        }
 
270
/*#ifdef(PHP4):
 
271
/**
 
272
        * Constructor (PHP4) direct_db (direct_db)
 
273
        *
 
274
        * @param boolean $f_peristent True to establish a persistent connection
 
275
        * @since v0.1.00
 
276
*\/
 
277
        function direct_db ($f_peristent = false) { $this->__construct ($f_peristent = false); }
 
278
:#\n*/
 
279
        //f// direct_db->__destruct ()
 
280
/**
 
281
        * Destructor (PHP5) __destruct (direct_db)
 
282
        * Closes the database connection on destruction.
 
283
        *
 
284
        * @uses  direct_dbraw_*::disconnect()
 
285
        * @since v0.1.00
 
286
*/
 
287
        /*#ifndef(PHP4) */public /* #*/function __destruct () { $this->v_disconnect (); }
 
288
 
 
289
        //f// direct_db->define_attributes ($f_attribute_list)
 
290
/**
 
291
        * Defines SQL attributes. (Only supported for SQL SELECT)
 
292
        *
 
293
        * @param  mixed $f_attribute_list Requested attributes (including AS
 
294
        *         definition) as array or a string for "*"
 
295
        * @uses   direct_debug()
 
296
        * @uses   USE_debug_reporting
 
297
        * @return boolean False if query is empty or on error
 
298
        * @since  v0.1.00
 
299
*/
 
300
        /*#ifndef(PHP4) */public /* #*/function define_attributes ($f_attribute_list)
 
301
        {
 
302
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_attributes (+f_attribute_list)- (#echo(__LINE__)#)"); }
 
303
 
 
304
                if ($this->query_type == "select")
 
305
                {
 
306
                        if (is_array ($f_attribute_list)) { $this->query_attributes = $f_attribute_list; }
 
307
                        else { $this->query_attributes = array ("*"); }
 
308
 
 
309
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_attributes ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
310
                }
 
311
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_attributes ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
312
        }
 
313
 
 
314
        //f// direct_db->define_grouping ($f_attribute_list)
 
315
/**
 
316
        * Defines the SQL GROUP BY clause. (Only supported for SQL SELECT)
 
317
        *
 
318
        * @param  mixed $f_attribute_list Requested grouping (including AS
 
319
        *         definition) as array or a string (for a single attribute)
 
320
        * @uses   direct_debug()
 
321
        * @uses   USE_debug_reporting
 
322
        * @return boolean False if query is empty or on error
 
323
        * @since  v0.1.00
 
324
*/
 
325
        /*#ifndef(PHP4) */public /* #*/function define_grouping ($f_attribute_list)
 
326
        {
 
327
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_grouping (+f_attribute_list)- (#echo(__LINE__)#)"); }
 
328
 
 
329
                if ($this->query_type == "select")
 
330
                {
 
331
                        if (is_array ($f_attribute_list)) { $this->query_grouping = $f_attribute_list; }
 
332
                        else { $this->query_grouping = array ($f_attribute_list); }
 
333
 
 
334
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_grouping ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
335
                }
 
336
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_grouping ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
337
        }
 
338
 
 
339
        //f// direct_db->define_join ($f_requirements)
 
340
/**
 
341
        * Defines the SQL JOIN clause. (Only supported for SQL SELECT)
 
342
        *
 
343
        * @param  string $f_type Type of JOIN
 
344
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
345
        * @param  string $f_requirements ON definitions given as an array
 
346
        * @uses   direct_debug()
 
347
        * @uses   USE_debug_reporting
 
348
        * @return boolean False if query is empty or on error
 
349
        * @since  v0.1.00
 
350
*/
 
351
        /*#ifndef(PHP4) */public /* #*/function define_join ($f_type,$f_table,$f_requirements)
 
352
        {
 
353
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_join ($f_type,$f_table,+f_requirements)- (#echo(__LINE__)#)"); }
 
354
                $f_return = false;
 
355
 
 
356
                if ($this->query_type == "select")
 
357
                {
 
358
                        if ((is_string ($f_requirements))||($f_type == "cross-join"))
 
359
                        {
 
360
                                $this->query_joins[] = array ("type" => $f_type,"table" => $f_table,"requirements" => $f_requirements);
 
361
                                $f_return = true;
 
362
                        }
 
363
                }
 
364
 
 
365
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_join ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
366
        }
 
367
 
 
368
        //f// direct_db->define_limit ($f_limit)
 
369
/**
 
370
        * Defines a row limit for queries.
 
371
        *
 
372
        * @param  integer $f_limit Limit for the query
 
373
        * @uses   direct_debug()
 
374
        * @uses   USE_debug_reporting
 
375
        * @return boolean False if query is empty or on error
 
376
        * @since  v0.1.00
 
377
*/
 
378
        /*#ifndef(PHP4) */public /* #*/function define_limit ($f_limit)
 
379
        {
 
380
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_limit ($f_limit)- (#echo(__LINE__)#)"); }
 
381
 
 
382
                if (($this->query_type == "delete")||($this->query_type == "select")||($this->query_type == "update"))
 
383
                {
 
384
                        $this->query_limit = $f_limit;
 
385
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_limit ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
386
                }
 
387
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_limit ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
388
        }
 
389
 
 
390
        //f// direct_db->define_offset ($f_offset)
 
391
/**
 
392
        * Defines an offset for queries.
 
393
        *
 
394
        * @param  integer $f_offset Offset for the query (0 for none)
 
395
        * @uses   direct_debug()
 
396
        * @uses   USE_debug_reporting
 
397
        * @return boolean False if query is empty or on error
 
398
        * @since  v0.1.00
 
399
*/
 
400
        /*#ifndef(PHP4) */public /* #*/function define_offset ($f_offset)
 
401
        {
 
402
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_offset ($f_offset)- (#echo(__LINE__)#)"); }
 
403
 
 
404
                if ($this->query_type == "select")
 
405
                {
 
406
                        $this->query_offset = $f_offset;
 
407
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_offset ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
408
                }
 
409
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_offset ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
410
        }
 
411
 
 
412
        //f// direct_db->define_ordering ($f_ordering_list)
 
413
/**
 
414
        * Defines the SQL ORDER BY items.
 
415
        *
 
416
        * @param  string $f_ordering_list XML-encoded elements how to order the list
 
417
        * @uses   direct_debug()
 
418
        * @uses   USE_debug_reporting
 
419
        * @return boolean False if query is empty or on error
 
420
        * @since  v0.1.00
 
421
*/
 
422
        /*#ifndef(PHP4) */public /* #*/function define_ordering ($f_ordering_list)
 
423
        {
 
424
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_ordering (+f_ordering_list)- (#echo(__LINE__)#)"); }
 
425
                $f_return = false;
 
426
 
 
427
                if ($this->query_type == "select")
 
428
                {
 
429
                        if (is_string ($f_ordering_list))
 
430
                        {
 
431
                                $this->query_ordering = $f_ordering_list;
 
432
                                $f_return = true;
 
433
                        }
 
434
                }
 
435
 
 
436
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_ordering ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
437
        }
 
438
 
 
439
        //f// direct_db->define_row_conditions ($f_requirements)
 
440
/**
 
441
        * Defines the SQL WHERE clause.
 
442
        *
 
443
        * @param  string $f_requirements WHERE definitions given as an array
 
444
        * @uses   direct_debug()
 
445
        * @uses   USE_debug_reporting
 
446
        * @return boolean False if query is empty or on error
 
447
        * @since  v0.1.00
 
448
*/
 
449
        /*#ifndef(PHP4) */public /* #*/function define_row_conditions ($f_requirements)
 
450
        {
 
451
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_row_conditions (+f_requirements)- (#echo(__LINE__)#)"); }
 
452
                $f_return = false;
 
453
 
 
454
                if (($this->query_type == "delete")||($this->query_type == "select")||($this->query_type == "update"))
 
455
                {
 
456
                        if (is_string ($f_requirements))
 
457
                        {
 
458
                                $this->query_row_conditions = $f_requirements;
 
459
                                $f_return = true;
 
460
                        }
 
461
                }
 
462
 
 
463
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_row_conditions ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
464
        }
 
465
 
 
466
        //f// direct_db->define_row_conditions_encode ($f_attribute,$f_value,$f_type,$f_logical_operator = "==",$f_condition_mode = "and")
 
467
/**
 
468
        * Returns valid XML sqlbox code for WHERE. Useful to secure values of
 
469
        * attributes against SQL injection.
 
470
        *
 
471
        * @param  string $f_attribute Attribute
 
472
        * @param  string $f_value Value of the attribute
 
473
        * @param  string $f_type Value type (attribute, number, string)
 
474
        * @param  string $f_logical_operator Logical operator
 
475
        * @param  string $f_condition_mode Condition of this element
 
476
        * @uses   direct_db::v_secure()
 
477
        * @uses   direct_debug()
 
478
        * @uses   direct_xml_bridge::array2xml_item_encoder()
 
479
        * @uses   USE_debug_reporting
 
480
        * @return boolean False if query is empty or on error
 
481
        * @since  v0.1.00
 
482
*/
 
483
        /*#ifndef(PHP4) */public /* #*/function define_row_conditions_encode ($f_attribute,$f_value,$f_type,$f_logical_operator = "==",$f_condition_mode = "and")
 
484
        {
 
485
                global $direct_classes,$direct_settings;
 
486
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_row_conditions_encode ($f_attribute,$f_value,$f_type,$f_logical_operator,$f_condition_mode)- (#echo(__LINE__)#)"); }
 
487
 
 
488
                $f_return = "";
 
489
 
 
490
                if (isset ($direct_classes['xml_bridge']))
 
491
                {
 
492
                        switch ($f_type)
 
493
                        {
 
494
                        case "attribute":
 
495
                        {
 
496
                                $f_value = preg_replace ("#\W#","",$f_value);
 
497
                                break 1;
 
498
                        }
 
499
                        case "number":
 
500
                        {
 
501
                                preg_match ("#^(-|)(\d+)$#i",$f_value,$f_result_array);
 
502
                                if (!empty ($f_result_array)) { $f_value = $f_result_array[0]; }
 
503
 
 
504
                                break 1;
 
505
                        }
 
506
                        case "sublevel": { break 1; }
 
507
                        default:
 
508
                        {
 
509
                                $f_type = "string";
 
510
                                if ($f_value !== NULL) { $this->v_secure ($f_value); }
 
511
                        }
 
512
                        }
 
513
 
 
514
                        if ($f_condition_mode != "or") { $f_condition_mode = "and"; }
 
515
 
 
516
                        switch ($f_logical_operator)
 
517
                        {
 
518
                        case "!=": { break 1; }
 
519
                        case "<": { break 1; }
 
520
                        case "<=": { break 1; }
 
521
                        case ">": { break 1; }
 
522
                        case ">=": { break 1; }
 
523
                        default: { $f_logical_operator = "=="; }
 
524
                        }
 
525
 
 
526
$f_xml_node_array = array (
 
527
"tag" => "element".$direct_settings['swg_id'].$this->query_element,
 
528
"attributes" => array ("attribute" => $f_attribute,"condition" => $f_condition_mode,"operator" => $f_logical_operator,"type" => $f_type)
 
529
);
 
530
 
 
531
                        if ($f_value === NULL)
 
532
                        {
 
533
                                $f_xml_node_array['attributes']['null'] = 1;
 
534
                                $f_xml_node_array['value'] = "";
 
535
                        }
 
536
                        else { $f_xml_node_array['value'] = $f_value; }
 
537
 
 
538
                        $this->query_element++;
 
539
                        $f_return = $direct_classes['xml_bridge']->array2xml_item_encoder ($f_xml_node_array,true,false);
 
540
                }
 
541
 
 
542
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_row_conditions_encode ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
543
        }
 
544
 
 
545
        //f// direct_db->define_search_conditions ($f_list)
 
546
/**
 
547
        * Defines search conditions for the database.
 
548
        *
 
549
        * @param  string $f_conditions Conditions to search for
 
550
        * @uses   direct_debug()
 
551
        * @uses   USE_debug_reporting
 
552
        * @return boolean False if query is empty or on error
 
553
        * @since  v0.1.00
 
554
*/
 
555
        /*#ifndef(PHP4) */public /* #*/function define_search_conditions ($f_conditions)
 
556
        {
 
557
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_search_conditions (+f_conditions)- (#echo(__LINE__)#)"); }
 
558
                $f_return = false;
 
559
 
 
560
                if ($this->query_type == "select")
 
561
                {
 
562
                        if (is_string ($f_conditions))
 
563
                        {
 
564
                                $this->query_search_conditions = $f_conditions;
 
565
                                $f_return = true;
 
566
                        }
 
567
                }
 
568
 
 
569
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_search_conditions ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
570
        }
 
571
 
 
572
        //f// direct_db->define_search_conditions_term ($f_term)
 
573
/**
 
574
        * Creates the search term definition XML code for the given term.
 
575
        *
 
576
        * @param  string $f_term Term to search for
 
577
        * @uses   direct_db::v_secure()
 
578
        * @uses   direct_debug()
 
579
        * @uses   direct_xml_bridge::array2xml_item_encoder()
 
580
        * @uses   USE_debug_reporting
 
581
        * @return boolean False if query is empty or on error
 
582
        * @since  v0.1.00
 
583
*/
 
584
        /*#ifndef(PHP4) */public /* #*/function define_search_conditions_term ($f_term)
 
585
        {
 
586
                global $direct_classes;
 
587
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_search_conditions_term (+f_term)- (#echo(__LINE__)#)"); }
 
588
 
 
589
                $f_return = "";
 
590
 
 
591
                if (isset ($direct_classes['xml_bridge']))
 
592
                {
 
593
$f_xml_node_array = array (
 
594
"tag" => "searchterm",
 
595
"value" => $f_term
 
596
);
 
597
 
 
598
                        $f_return = $direct_classes['xml_bridge']->array2xml_item_encoder ($f_xml_node_array,true,false);
 
599
                }
 
600
 
 
601
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_search_conditions_term ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
602
        }
 
603
 
 
604
        //f// direct_db->define_set_attributes ($f_attribute_list)
 
605
/**
 
606
        * Defines the SQL SET clause.
 
607
        *
 
608
        * @param  string $f_attribute_list Attributes to set
 
609
        * @uses   direct_debug()
 
610
        * @uses   USE_debug_reporting
 
611
        * @return boolean False if query is empty or on error
 
612
        * @since  v0.1.00
 
613
*/
 
614
        /*#ifndef(PHP4) */public /* #*/function define_set_attributes ($f_attribute_list)
 
615
        {
 
616
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_set_attributes (+f_attribute_list)- (#echo(__LINE__)#)"); }
 
617
 
 
618
                $f_continue_check = true;
 
619
                $f_return = false;
 
620
 
 
621
                if (($this->query_type != "insert")&&($this->query_type != "replace")&&($this->query_type != "update")) { $f_continue_check = false; }
 
622
                if (!empty ($this->query_values)) { $f_continue_check = false; }
 
623
 
 
624
                if ($f_continue_check)
 
625
                {
 
626
                        if (is_string ($f_attribute_list))
 
627
                        {
 
628
                                $this->query_set_attributes = $f_attribute_list;
 
629
                                $f_return = true;
 
630
                        }
 
631
                }
 
632
 
 
633
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_set_attributes ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
634
        }
 
635
 
 
636
        //f// direct_db->define_set_attributes_encode ($f_attribute,$f_value,$f_type)
 
637
/**
 
638
        * Returns valid XML sqlbox code for SET. Useful to secure values against SQL
 
639
        * injection.
 
640
        *
 
641
        * @param  string $f_attribute Attribute
 
642
        * @param  string $f_value Value string
 
643
        * @param  string $f_type Value type (attribute, number, string)
 
644
        * @uses   direct_db::v_secure()
 
645
        * @uses   direct_debug()
 
646
        * @uses   direct_xml_bridge::array2xml_item_encoder()
 
647
        * @uses   USE_debug_reporting
 
648
        * @return boolean False if query is empty or on error
 
649
        * @since  v0.1.00
 
650
*/
 
651
        /*#ifndef(PHP4) */public /* #*/function define_set_attributes_encode ($f_attribute,$f_value,$f_type)
 
652
        {
 
653
                global $direct_classes,$direct_settings;
 
654
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_set_attributes_encode ($f_attribute,$f_value,$f_type)- (#echo(__LINE__)#)"); }
 
655
 
 
656
                $f_return = "";
 
657
 
 
658
                if (isset ($direct_classes['xml_bridge']))
 
659
                {
 
660
                        switch ($f_type)
 
661
                        {
 
662
                        case "attribute":
 
663
                        {
 
664
                                $f_value = preg_replace ("#\W#","",$f_value);
 
665
                                break 1;
 
666
                        }
 
667
                        case "number":
 
668
                        {
 
669
                                preg_match ("#^(-|)(\d+)$#i",$f_value,$f_result_array);
 
670
                                if (!empty ($f_result_array)) { $f_value = $f_result_array[0]; }
 
671
 
 
672
                                break 1;
 
673
                        }
 
674
                        default:
 
675
                        {
 
676
                                $f_type = "string";
 
677
                                if ($f_value !== NULL) { $this->v_secure ($f_value); }
 
678
                        }
 
679
                        }
 
680
 
 
681
$f_xml_node_array = array (
 
682
"tag" => "element".$direct_settings['swg_id'].$this->query_element,
 
683
"attributes" => array ("attribute" => $f_attribute,"type" => $f_type)
 
684
);
 
685
 
 
686
                        if ($f_value === NULL)
 
687
                        {
 
688
                                $f_xml_node_array['attributes']['null'] = 1;
 
689
                                $f_xml_node_array['value'] = "";
 
690
                        }
 
691
                        else { $f_xml_node_array['value'] = $f_value; }
 
692
 
 
693
                        $this->query_element++;
 
694
                        $f_return = $direct_classes['xml_bridge']->array2xml_item_encoder ($f_xml_node_array,true,false);
 
695
                }
 
696
 
 
697
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_set_attributes_encode ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
698
        }
 
699
 
 
700
        //f// direct_db->define_values ($f_requirements)
 
701
/**
 
702
        * Defines the SQL VALUES element.
 
703
        *
 
704
        * @param  string $f_values WHERE definitions given as an array
 
705
        * @uses   direct_debug()
 
706
        * @uses   USE_debug_reporting
 
707
        * @return boolean False if query is empty or on error
 
708
        * @since  v0.1.00
 
709
*/
 
710
        /*#ifndef(PHP4) */public /* #*/function define_values ($f_values)
 
711
        {
 
712
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_values (+f_values)- (#echo(__LINE__)#)"); }
 
713
 
 
714
                $f_return = false;
 
715
                $f_continue_check = true;
 
716
 
 
717
                if (($this->query_type != "insert")&&($this->query_type != "replace")) { $f_continue_check = false; }
 
718
                if (!empty ($this->query_set_attributes)) { $f_continue_check = false; }
 
719
 
 
720
                if ($f_continue_check)
 
721
                {
 
722
                        if (is_string ($f_values))
 
723
                        {
 
724
                                $this->query_values = $f_values;
 
725
                                $f_return = true;
 
726
                        }
 
727
                }
 
728
 
 
729
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_values ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
730
        }
 
731
 
 
732
        //f// direct_db->define_values_encode ($f_value,$f_type)
 
733
/**
 
734
        * Returns valid XML sqlbox code for VALUES. Useful to secure values against
 
735
        * SQL injection.
 
736
        *
 
737
        * @param  string $f_value Value string
 
738
        * @param  string $f_type Value type (attribute, number, string)
 
739
        * @uses   direct_db::v_secure()
 
740
        * @uses   direct_debug()
 
741
        * @uses   direct_xml_bridge::array2xml_item_encoder()
 
742
        * @uses   USE_debug_reporting
 
743
        * @return boolean False if query is empty or on error
 
744
        * @since  v0.1.00
 
745
*/
 
746
        /*#ifndef(PHP4) */public /* #*/function define_values_encode ($f_value,$f_type)
 
747
        {
 
748
                global $direct_classes,$direct_settings;
 
749
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_values_encode ($f_value,$f_type)- (#echo(__LINE__)#)"); }
 
750
 
 
751
                $f_return = "";
 
752
 
 
753
                if (isset ($direct_classes['xml_bridge']))
 
754
                {
 
755
                        switch ($f_type)
 
756
                        {
 
757
                        case "attribute":
 
758
                        {
 
759
                                $f_value = preg_replace ("#\W#","",$f_value);
 
760
                                break 1;
 
761
                        }
 
762
                        case "number":
 
763
                        {
 
764
                                preg_match ("#^(-|)(\d+)$#i",$f_value,$f_result_array);
 
765
                                if (!empty ($f_result_array)) { $f_value = $f_result_array[0]; }
 
766
 
 
767
                                break 1;
 
768
                        }
 
769
                        case "newrow": { break 1; }
 
770
                        default:
 
771
                        {
 
772
                                $f_type = "string";
 
773
                                if ($f_value !== NULL) { $this->v_secure ($f_value); }
 
774
                        }
 
775
                        }
 
776
 
 
777
$f_xml_node_array = array (
 
778
"tag" => "element".$direct_settings['swg_id'].$this->query_element,
 
779
"attributes" => array ("type" => $f_type)
 
780
);
 
781
 
 
782
                        if ($f_value === NULL)
 
783
                        {
 
784
                                $f_xml_node_array['attributes']['null'] = 1;
 
785
                                $f_xml_node_array['value'] = "";
 
786
                        }
 
787
                        else { $f_xml_node_array['value'] = $f_value; }
 
788
 
 
789
                        $this->query_element++;
 
790
                        $f_return = $direct_classes['xml_bridge']->array2xml_item_encoder ($f_xml_node_array,true,false);
 
791
                }
 
792
 
 
793
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_values_encode ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
794
        }
 
795
 
 
796
        //f// direct_db->define_values_keys ($f_offset)
 
797
/**
 
798
        * Defines the key list for the SQL VALUES statement.
 
799
        *
 
800
        * @param  array $f_keys_list Key list for VALUES
 
801
        * @uses   direct_debug()
 
802
        * @uses   USE_debug_reporting
 
803
        * @return boolean False if query is empty or on error
 
804
        * @since  v0.1.00
 
805
*/
 
806
        /*#ifndef(PHP4) */public /* #*/function define_values_keys ($f_keys_list)
 
807
        {
 
808
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->define_values_keys (+f_keys_list)- (#echo(__LINE__)#)"); }
 
809
                $f_return = false;
 
810
 
 
811
                if (($this->query_type == "insert")||($this->query_type == "replace"))
 
812
                {
 
813
                        if (is_array ($f_keys_list))
 
814
                        {
 
815
                                $this->query_values_keys = $f_keys_list;
 
816
                                $f_return = true;
 
817
                        }
 
818
                }
 
819
 
 
820
                return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->define_values_keys ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
821
        }
 
822
 
 
823
        //f// direct_db->init_delete ($f_table)
 
824
/**
 
825
        * Initiates a DELETE request.
 
826
        *
 
827
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
828
        * @uses   direct_class_function_check()
 
829
        * @uses   direct_debug()
 
830
        * @uses   USE_debug_reporting
 
831
        * @return boolean False if query cache is not empty (Query not executed?)
 
832
        * @since  v0.1.00
 
833
*/
 
834
        /*#ifndef(PHP4) */public /* #*/function init_delete ($f_table)
 
835
        {
 
836
                global $direct_classes;
 
837
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->init_delete ($f_table)- (#echo(__LINE__)#)"); }
 
838
 
 
839
                if ((direct_class_function_check ($direct_classes['db'],"v_query_build"))&&(!$this->query_type))
 
840
                {
 
841
                        $this->data = "";
 
842
                        $this->query_attributes = array ("*");
 
843
                        $this->query_grouping = "";
 
844
                        $this->query_joins = array ();
 
845
                        $this->query_limit = 0;
 
846
                        $this->query_offset = 0;
 
847
                        $this->query_ordering = "";
 
848
                        $this->query_row_conditions = "";
 
849
                        $this->query_search_conditions = array ();
 
850
                        $this->query_set_attributes = array ();
 
851
                        $this->query_table = $f_table;
 
852
                        $this->query_type = "delete";
 
853
                        $this->query_values = "";
 
854
                        $this->query_values_keys = array ();
 
855
 
 
856
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_delete ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
857
                }
 
858
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_delete ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
859
        }
 
860
 
 
861
        //f// direct_db->init_insert ($f_table)
 
862
/**
 
863
        * Initiates a INSERT request.
 
864
        *
 
865
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
866
        * @uses   direct_class_function_check()
 
867
        * @uses   direct_debug()
 
868
        * @uses   USE_debug_reporting
 
869
        * @return boolean False if query cache is not empty (Query not executed?)
 
870
        * @since  v0.1.00
 
871
*/
 
872
        /*#ifndef(PHP4) */public /* #*/function init_insert ($f_table)
 
873
        {
 
874
                global $direct_classes;
 
875
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->init_insert ($f_table)- (#echo(__LINE__)#)"); }
 
876
 
 
877
                if ((direct_class_function_check ($direct_classes['db'],"v_query_build"))&&(!$this->query_type))
 
878
                {
 
879
                        $this->data = "";
 
880
                        $this->query_attributes = array ("*");
 
881
                        $this->query_grouping = "";
 
882
                        $this->query_joins = array ();
 
883
                        $this->query_limit = 0;
 
884
                        $this->query_offset = 0;
 
885
                        $this->query_ordering = "";
 
886
                        $this->query_row_conditions = "";
 
887
                        $this->query_search_conditions = array ();
 
888
                        $this->query_set_attributes = array ();
 
889
                        $this->query_table = $f_table;
 
890
                        $this->query_type = "insert";
 
891
                        $this->query_values = "";
 
892
                        $this->query_values_keys = array ();
 
893
 
 
894
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_insert ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
895
                }
 
896
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_insert ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
897
        }
 
898
 
 
899
        //f// direct_db->init_replace ($f_table)
 
900
/**
 
901
        * Initiates a REPLACE request.
 
902
        *
 
903
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
904
        * @uses   direct_class_function_check()
 
905
        * @uses   direct_debug()
 
906
        * @uses   USE_debug_reporting
 
907
        * @return boolean False if query cache is not empty (Query not executed?)
 
908
        * @since  v0.1.00
 
909
*/
 
910
        /*#ifndef(PHP4) */public /* #*/function init_replace ($f_table)
 
911
        {
 
912
                global $direct_classes;
 
913
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->init_replace ($f_table)- (#echo(__LINE__)#)"); }
 
914
 
 
915
                if ((direct_class_function_check ($direct_classes['db'],"v_query_build"))&&(!$this->query_type))
 
916
                {
 
917
                        $this->data = "";
 
918
                        $this->query_attributes = array ("*");
 
919
                        $this->query_grouping = "";
 
920
                        $this->query_joins = array ();
 
921
                        $this->query_limit = 0;
 
922
                        $this->query_offset = 0;
 
923
                        $this->query_ordering = "";
 
924
                        $this->query_row_conditions = "";
 
925
                        $this->query_search_conditions = array ();
 
926
                        $this->query_set_attributes = array ();
 
927
                        $this->query_table = $f_table;
 
928
                        $this->query_type = "replace";
 
929
                        $this->query_values = "";
 
930
                        $this->query_values_keys = array ();
 
931
 
 
932
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_replace ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
933
                }
 
934
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_replace ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
935
        }
 
936
 
 
937
        //f// direct_db->init_select ($f_table)
 
938
/**
 
939
        * Initiates a SELECT request.
 
940
        *
 
941
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
942
        * @uses   direct_class_function_check()
 
943
        * @uses   direct_debug()
 
944
        * @uses   USE_debug_reporting
 
945
        * @return boolean False if query cache is not empty (Query not executed?)
 
946
        * @since  v0.1.00
 
947
*/
 
948
        /*#ifndef(PHP4) */public /* #*/function init_select ($f_table)
 
949
        {
 
950
                global $direct_classes;
 
951
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->init_select ($f_table)- (#echo(__LINE__)#)"); }
 
952
 
 
953
                if ((direct_class_function_check ($direct_classes['db'],"v_query_build"))&&(!$this->query_type))
 
954
                {
 
955
                        $this->data = "";
 
956
                        $this->query_attributes = array ("*");
 
957
                        $this->query_grouping = "";
 
958
                        $this->query_joins = array ();
 
959
                        $this->query_limit = 0;
 
960
                        $this->query_offset = 0;
 
961
                        $this->query_ordering = "";
 
962
                        $this->query_row_conditions = "";
 
963
                        $this->query_search_conditions = array ();
 
964
                        $this->query_set_attributes = array ();
 
965
                        $this->query_table = $f_table;
 
966
                        $this->query_type = "select";
 
967
                        $this->query_values = "";
 
968
                        $this->query_values_keys = array ();
 
969
 
 
970
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_select ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
971
                }
 
972
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_select ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
973
        }
 
974
 
 
975
        //f// direct_db->init_update ($f_table)
 
976
/**
 
977
        * Initiates a UPDATE request.
 
978
        *
 
979
        * @param  string $f_table Name of the table (" AS Name" is valid)
 
980
        * @uses   direct_class_function_check()
 
981
        * @uses   direct_debug()
 
982
        * @uses   USE_debug_reporting
 
983
        * @return boolean False if query cache is not empty (Query not executed?)
 
984
        * @since  v0.1.00
 
985
*/
 
986
        /*#ifndef(PHP4) */public /* #*/function init_update ($f_table)
 
987
        {
 
988
                global $direct_classes;
 
989
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->init_update ($f_table)- (#echo(__LINE__)#)"); }
 
990
 
 
991
                if ((direct_class_function_check ($direct_classes['db'],"v_query_build"))&&(!$this->query_type))
 
992
                {
 
993
                        $this->data = "";
 
994
                        $this->query_attributes = array ("*");
 
995
                        $this->query_grouping = "";
 
996
                        $this->query_joins = array ();
 
997
                        $this->query_limit = 0;
 
998
                        $this->query_offset = 0;
 
999
                        $this->query_ordering = "";
 
1000
                        $this->query_row_conditions = "";
 
1001
                        $this->query_search_conditions = array ();
 
1002
                        $this->query_set_attributes = array ();
 
1003
                        $this->query_table = $f_table;
 
1004
                        $this->query_type = "update";
 
1005
                        $this->query_values = "";
 
1006
                        $this->query_values_keys = array ();
 
1007
 
 
1008
                        return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_update ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/;
 
1009
                }
 
1010
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->init_update ()- (#echo(__LINE__)#)",:#*/false/*#ifdef(DEBUG):,true):#*/; }
 
1011
        }
 
1012
 
 
1013
        //f// direct_db->optimize_random ($f_table)
 
1014
/**
 
1015
        * Optimizes a given table randomly (1/3).
 
1016
        *
 
1017
        * @param  string $f_table Name of the table
 
1018
        * @uses   direct_db::v_optimize()
 
1019
        * @uses   direct_debug()
 
1020
        * @uses   USE_debug_reporting
 
1021
        * @return boolean True on success
 
1022
        * @since  v0.1.00
 
1023
*/
 
1024
        /*#ifndef(PHP4) */public /* #*/function optimize_random ($f_table)
 
1025
        {
 
1026
                if (USE_debug_reporting) { direct_debug (5,"sWG/#echo(__FILEPATH__)# -db_class->optimize_random ($f_table)- (#echo(__LINE__)#)"); }
 
1027
 
 
1028
                if ((mt_rand (0,30)) > 20) { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->optimize_random ()- (#echo(__LINE__)#)",(:#*/$this->v_optimize ($f_table)/*#ifdef(DEBUG):),true):#*/; }
 
1029
                else { return /*#ifdef(DEBUG):direct_debug (7,"sWG/#echo(__FILEPATH__)# -direct_db->optimize_random ()- (#echo(__LINE__)#)",:#*/true/*#ifdef(DEBUG):,true):#*/; }
 
1030
        }
 
1031
 
 
1032
        //f// direct_db->query_exec ($f_answer)
 
1033
/**
 
1034
        * Transmits defined data to the SQL builder and returns the result in a
 
1035
        * developer specified format via $f_answer.
 
1036
        *
 
1037
        * @param  string $f_answer Defines the requested type that should be returned
 
1038
    *         The following types are supported: "ar", "co", "ma", "ms", "nr",
 
1039
    *         "sa" or "ss".
 
1040
        * @uses   direct_class_function_check()
 
1041
        * @uses   direct_dbraw_*::query_build()
 
1042
        * @uses   direct_debug()
 
1043
        * @uses   USE_debug_reporting
 
1044
        * @return mixed Result returned by the server in the specified format
 
1045
        * @since  v0.1.00
 
1046
*/
 
1047
        /*#ifndef(PHP4) */public /* #*/function query_exec ($f_answer = "sa")
 
1048
        {
 
1049
                global $direct_classes;
 
1050
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->query_exec ($f_answer)- (#echo(__LINE__)#)"); }
 
1051
 
 
1052
                $f_return = false;
 
1053
 
 
1054
                if (direct_class_function_check ($direct_classes['db'],"v_query_build"))
 
1055
                {
 
1056
                        $f_data = array ();
 
1057
                        $f_data['answer'] = $f_answer;
 
1058
 
 
1059
                        $f_data['attributes'] = $this->query_attributes;
 
1060
                        $this->query_attributes = "";
 
1061
 
 
1062
                        $f_data['grouping'] = $this->query_grouping;
 
1063
                        $this->query_grouping = "";
 
1064
 
 
1065
                        $f_data['limit'] = $this->query_limit;
 
1066
                        $this->query_limit = "";
 
1067
 
 
1068
                        $f_data['offset'] = $this->query_offset;
 
1069
                        $this->query_offset = "";
 
1070
 
 
1071
                        $f_data['ordering'] = $this->query_ordering;
 
1072
                        $this->query_ordering = "";
 
1073
 
 
1074
                        $f_data['joins'] = $this->query_joins;
 
1075
                        $this->query_joins = array ();
 
1076
 
 
1077
                        $f_data['row_conditions'] = $this->query_row_conditions;
 
1078
                        $this->query_row_conditions = "";
 
1079
 
 
1080
                        $f_data['search_conditions'] = $this->query_search_conditions;
 
1081
                        $this->query_search_conditions = array ();
 
1082
 
 
1083
                        $f_data['set_attributes'] = $this->query_set_attributes;
 
1084
                        $this->query_set_attributes = array ();
 
1085
 
 
1086
                        $f_data['table'] = $this->query_table;
 
1087
                        $this->query_table = "";
 
1088
 
 
1089
                        $f_data['type'] = $this->query_type;
 
1090
                        $this->query_type = "";
 
1091
 
 
1092
                        $f_data['values'] = $this->query_values;
 
1093
                        $this->query_values = "";
 
1094
 
 
1095
                        $f_data['values_keys'] = $this->query_values_keys;
 
1096
                        $this->query_values_keys = array ();
 
1097
 
 
1098
                        $this->data = $this->v_query_build ($f_data);
 
1099
                        $f_return = $this->data;
 
1100
                }
 
1101
 
 
1102
                return /*#ifdef(DEBUG):direct_debug (9,"sWG/#echo(__FILEPATH__)# -direct_db->query_exec ()- (#echo(__LINE__)#)",:#*/$f_return/*#ifdef(DEBUG):,true):#*/;
 
1103
        }
 
1104
 
 
1105
        //f// direct_db->v_connect ()
 
1106
/**
 
1107
        * Opens the connection to a database server and selects a database.
 
1108
        *
 
1109
        * @uses   direct_debug()
 
1110
        * @uses   direct_virtual_class::v_call_get()
 
1111
        * @uses   USE_debug_reporting
 
1112
        * @return boolean True on success
 
1113
        * @since  v0.1.00
 
1114
*/
 
1115
        /*#ifndef(PHP4) */public /* #*/function v_connect ()
 
1116
        {
 
1117
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_connect ()- (#echo(__LINE__)#)"); }
 
1118
                $f_call = $this->v_call_get ("v_connect");
 
1119
 
 
1120
                if ($f_call) { return $f_call[0]->{$f_call[1]} (); }
 
1121
                else { return false; }
 
1122
        }
 
1123
 
 
1124
        //f// direct_db->v_disconnect ()
 
1125
/**
 
1126
        * Closes an active database connection to the server.
 
1127
        *
 
1128
        * @uses   direct_debug()
 
1129
        * @uses   direct_virtual_class::v_call_get()
 
1130
        * @uses   USE_debug_reporting
 
1131
        * @return boolean True on success
 
1132
        * @since  v0.1.00
 
1133
*/
 
1134
        /*#ifndef(PHP4) */public /* #*/function v_disconnect ()
 
1135
        {
 
1136
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_disconnect ()- (#echo(__LINE__)#)"); }
 
1137
                $f_call = $this->v_call_get ("v_disconnect");
 
1138
 
 
1139
                if ($f_call) { return $f_call[0]->{$f_call[1]} (); }
 
1140
                else { return false; }
 
1141
        }
 
1142
 
 
1143
        //f// direct_db->v_optimize ($f_table)
 
1144
/**
 
1145
        * Optimizes a given table.
 
1146
        *
 
1147
        * @param  string $f_table Name of the table
 
1148
        * @uses   direct_debug()
 
1149
        * @uses   direct_virtual_class::v_call_get()
 
1150
        * @uses   USE_debug_reporting
 
1151
        * @return boolean True on success
 
1152
        * @since  v0.1.00
 
1153
*/
 
1154
        /*#ifndef(PHP4) */public /* #*/function v_optimize ($f_table)
 
1155
        {
 
1156
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_optimize ($f_table)- (#echo(__LINE__)#)"); }
 
1157
                $f_call = $this->v_call_get ("v_optimize");
 
1158
 
 
1159
                if ($f_call) { return $f_call[0]->{$f_call[1]} ($f_table); }
 
1160
                else { return false; }
 
1161
        }
 
1162
 
 
1163
        //f// direct_db->v_query_build ($f_data)
 
1164
/**
 
1165
        * Builds and runs the SQL statement using the connected database specific
 
1166
        * layer.
 
1167
        *
 
1168
        * @param  array $f_data Array containing query specific information.
 
1169
        * @uses   direct_debug()
 
1170
        * @uses   direct_virtual_class::v_call_get()
 
1171
        * @uses   USE_debug_reporting
 
1172
        * @return mixed Result returned by the server in the specified format
 
1173
        * @since  v0.1.00
 
1174
*/
 
1175
        /*#ifndef(PHP4) */public /* #*/function v_query_build ($f_data)
 
1176
        {
 
1177
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_query_build (+f_query)- (#echo(__LINE__)#)"); }
 
1178
                $f_call = $this->v_call_get ("v_query_build");
 
1179
 
 
1180
                if ($f_call) { return $f_call[0]->{$f_call[1]} ($f_data); }
 
1181
                else { return false; }
 
1182
        }
 
1183
 
 
1184
        //f// direct_db->v_query_exec ($f_answer,$f_query)
 
1185
/**
 
1186
        * Transmits an SQL query and returns the result in a developer specified
 
1187
        * format via $f_answer.
 
1188
        *
 
1189
        * @param  string $f_answer Defines the requested type that should be returned
 
1190
    *         The following types are supported: "ar", "co", "ma", "ms", "nr",
 
1191
    *         "sa" or "ss".
 
1192
        * @param  string $f_query Valid SQL query
 
1193
        * @uses   direct_debug()
 
1194
        * @uses   direct_virtual_class::v_call_get()
 
1195
        * @uses   USE_debug_reporting
 
1196
        * @return mixed Result returned by the server in the specified format
 
1197
        * @since  v0.1.00
 
1198
*/
 
1199
        /*#ifndef(PHP4) */public /* #*/function v_query_exec ($f_answer,$f_query)
 
1200
        {
 
1201
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_query_exec ($f_answer,+f_query)- (#echo(__LINE__)#)"); }
 
1202
                $f_call = $this->v_call_get ("v_query_exec");
 
1203
 
 
1204
                if ($f_call) { return $f_call[0]->{$f_call[1]} ($f_answer,$f_query); }
 
1205
                else { return false; }
 
1206
        }
 
1207
 
 
1208
        //f// direct_db_mysql->v_secure (&$f_data)
 
1209
/**
 
1210
        * Secures a given string to protect against SQL injections.
 
1211
        *
 
1212
        * @param  mixed &$f_data Input array or string
 
1213
        * @uses   direct_debug()
 
1214
        * @uses   direct_virtual_class::v_call_get()
 
1215
        * @uses   USE_debug_reporting
 
1216
        * @since  v0.1.00
 
1217
*/
 
1218
        /*#ifndef(PHP4) */public /* #*/function v_secure (&$f_data)
 
1219
        {
 
1220
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_secure (+f_data)- (#echo(__LINE__)#)"); }
 
1221
 
 
1222
                $f_call = $this->v_call_get ("v_secure");
 
1223
                if ($f_call) { $f_call[0]->{$f_call[1]} ($f_data); }
 
1224
        }
 
1225
 
 
1226
        //f// direct_db_mysql->v_transaction_begin ()
 
1227
/**
 
1228
        * Starts a transaction.
 
1229
        *
 
1230
        * @uses   direct_debug()
 
1231
        * @uses   direct_virtual_class::v_call_get()
 
1232
        * @uses   USE_debug_reporting
 
1233
        * @since  v0.1.00
 
1234
*/
 
1235
        /*#ifndef(PHP4) */public /* #*/function v_transaction_begin ()
 
1236
        {
 
1237
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_transaction_begin ()- (#echo(__LINE__)#)"); }
 
1238
                $f_call = $this->v_call_get ("v_transaction_begin");
 
1239
 
 
1240
                if ($f_call) { return $f_call[0]->{$f_call[1]} (); }
 
1241
                else { return false; }
 
1242
        }
 
1243
 
 
1244
        //f// direct_db_mysql->v_transaction_commit ()
 
1245
/**
 
1246
        * Commits all transaction statements.
 
1247
        *
 
1248
        * @uses   direct_debug()
 
1249
        * @uses   direct_virtual_class::v_call_get()
 
1250
        * @uses   USE_debug_reporting
 
1251
        * @since  v0.1.00
 
1252
*/
 
1253
        /*#ifndef(PHP4) */public /* #*/function v_transaction_commit ()
 
1254
        {
 
1255
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_transaction_commit ()- (#echo(__LINE__)#)"); }
 
1256
                $f_call = $this->v_call_get ("v_transaction_commit");
 
1257
 
 
1258
                if ($f_call) { return $f_call[0]->{$f_call[1]} (); }
 
1259
                else { return false; }
 
1260
        }
 
1261
 
 
1262
        //f// direct_db_mysql->v_transaction_rollback ()
 
1263
/**
 
1264
        * Calls the ROLLBACK statement.
 
1265
        *
 
1266
        * @uses   direct_debug()
 
1267
        * @uses   direct_virtual_class::v_call_get()
 
1268
        * @uses   USE_debug_reporting
 
1269
        * @since  v0.1.00
 
1270
*/
 
1271
        /*#ifndef(PHP4) */public /* #*/function v_transaction_rollback ()
 
1272
        {
 
1273
                if (USE_debug_reporting) { direct_debug (8,"sWG/#echo(__FILEPATH__)# -db_class->v_transaction_rollback ()- (#echo(__LINE__)#)"); }
 
1274
                $f_call = $this->v_call_get ("v_transaction_rollback");
 
1275
 
 
1276
                if ($f_call) { return $f_call[0]->{$f_call[1]} (); }
 
1277
                else { return false; }
 
1278
        }
 
1279
}
 
1280
 
 
1281
/* -------------------------------------------------------------------------
 
1282
Mark this class as the most up-to-date one
 
1283
------------------------------------------------------------------------- */
 
1284
 
 
1285
$direct_classes['@names']['db'] = "direct_db";
 
1286
define ("CLASS_direct_db",true);
 
1287
}
 
1288
 
 
1289
//j// EOF
 
1290
?>
 
 
'\\ No newline at end of file'

Loggerhead 1.17 is a web-based interface for Bazaar branches