r831 - in branches: 1.7 1.7/tests 1.7/tests/data 1.7/tests/visual 1.7/tests/visual/menu experimen...

r831 - in branches: 1.7 1.7/tests 1.7/tests/data 1.7/tests/visual 1.7/tests/visual/menu experimen...


Author: paul.bakaus
Date: Thu Oct 23 07:07:20 2008
New Revision: 831
Added:
branches/experimental/gridmodel-spec
branches/experimental/tests/data/
branches/experimental/tests/data/emails-json.php
branches/experimental/tests/data/emails-xml.php
branches/experimental/tests/data/emails.php
branches/experimental/tests/data/employees-json.php
branches/experimental/tests/data/txtdb/
branches/experimental/tests/data/txtdb/addressbook.txt
branches/experimental/tests/data/txtdb/const.php
branches/experimental/tests/data/txtdb/database.php
branches/experimental/tests/data/txtdb/employees.txt
branches/experimental/tests/data/txtdb/expression.php
branches/experimental/tests/data/txtdb/init.php
branches/experimental/tests/data/txtdb/resultset.php
branches/experimental/tests/data/txtdb/sql.php
branches/experimental/tests/data/txtdb/stringparser.php
branches/experimental/tests/data/txtdb/txt-db-api.php
branches/experimental/tests/data/txtdb/util.php
branches/experimental/tests/datepicker.html
branches/experimental/tests/datepicker.js
branches/experimental/tests/grid.html
branches/experimental/tests/grid.js
branches/experimental/tests/gridmodel-local.js
branches/experimental/tests/gridmodel.html
branches/experimental/tests/gridmodel.js
branches/experimental/tests/visual/grid.html
branches/experimental/tests/visual/keyboard_selection.html
branches/experimental/tests/visual/menu/
branches/experimental/tests/visual/menu/css/
branches/experimental/tests/visual/menu/css/jquery-ui-themeroller.css
branches/experimental/tests/visual/menu/css/ui.menus.css
branches/experimental/tests/visual/menu/images/

branches/experimental/tests/visual/menu/images/222222_11x11_icon_resize_se.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/333333_40x100_textures_02_glass_25.png
(contents, props changed)

branches/experimental/tests/visual/menu/images/444444_40x100_textures_02_glass_25.png
(contents, props changed)

branches/experimental/tests/visual/menu/images/a21111_40x100_textures_02_glass_35.png
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_arrows_leftright.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_arrows_updown.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_close.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_doc.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_folder_closed.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_folder_open.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_minus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_11x11_icon_plus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_7x7_arrow_down.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_7x7_arrow_left.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/eeeeee_7x7_arrow_right.gif
(contents, props changed)
branches/experimental/tests/visual/menu/images/eeeeee_7x7_arrow_up.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_arrows_leftright.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_arrows_updown.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_close.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_doc.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_folder_closed.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_folder_open.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_minus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_11x11_icon_plus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_7x7_arrow_down.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_7x7_arrow_left.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffd40f_7x7_arrow_right.gif
(contents, props changed)
branches/experimental/tests/visual/menu/images/ffd40f_7x7_arrow_up.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_arrows_leftright.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_arrows_updown.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_close.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_doc.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_folder_closed.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_folder_open.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_minus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_11x11_icon_plus.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_7x7_arrow_down.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_7x7_arrow_left.gif
(contents, props changed)

branches/experimental/tests/visual/menu/images/ffffff_7x7_arrow_right.gif
(contents, props changed)
branches/experimental/tests/visual/menu/images/ffffff_7x7_arrow_up.gif
(contents, props changed)
branches/experimental/tests/visual/menu/menu.html
branches/experimental/ui.datepicker.js
branches/experimental/ui.grid.js
branches/experimental/ui.gridmodel.js
branches/experimental/ui.history.js
branches/experimental/ui.menu.js
branches/experimental/ui.selectable.js
Removed:
branches/1.7/gridmodel-spec
branches/1.7/tests/data/
branches/1.7/tests/datepicker.html
branches/1.7/tests/datepicker.js
branches/1.7/tests/grid.html
branches/1.7/tests/grid.js
branches/1.7/tests/gridmodel-local.js
branches/1.7/tests/gridmodel.html
branches/1.7/tests/gridmodel.js
branches/1.7/tests/visual/keyboard_selection.html
branches/1.7/tests/visual/menu/
branches/1.7/ui.datepicker.js
branches/1.7/ui.grid.js
branches/1.7/ui.gridmodel.js
branches/1.7/ui.history.js
branches/1.7/ui.menu.js
branches/1.7/ui.selectable.js
Log:
moved new datepicker, grid, gridmodel, history, menu and new selectables
over to experimental
Added: branches/experimental/gridmodel-spec
==============================================================================
--- (empty file)
+++ branches/experimental/gridmodel-spec    Thu Oct 23 07:07:20 2008
@@ -0,0 +1,77 @@
+interface GridModel {
+    void fetch(Request request, Callback response);
+    void update(Update update);
+}
+
+interface Callback {
+    void call(Response argument);
+}
+
+enum SortDirection { ASC, DESC }
+
+enum Operation { LIKE, EQUAL, GT, LT }
+
+enum FilterType { STRING, NUMBER, DATE, BOOLEAN, NONE }
+
+class Column {
+    // must be unique for a table
+    String id;
+    
+    String label;
+    
+    // TODO define how state-changes on width and visible are handled
+    // TODO where to define defaults?
+    int width;
+    boolean visible;
+    
+    boolean categorizable;
+    // must be false for categorizable false
+    boolean categorized;
+    
+    FilterType type;
+    // must be null for FilterType NONE
+    Filter filter;
+}
+
+// TODO define query string encoding
+class Filter {
+    Column target;
+    Operation op;
+    Object value;
+}
+
+class Record {
+    Map<Column, Object> columns;
+}
+
+class Request {
+    // paging
+    int start;
+    int limit;
+    
+    // sorting
+    Column sortColumn;
+    SortDirection sortDirection;
+    
+    // grouping, aggregating
+    Set<Column> categories;
+    
+    // filtering
+    Set<Filter> filters;
+    
+    // custom
+    Map<String, Object> custom;
+}
+
+class Response {
+    int totalRecords;
+    
+    Set<Column> columns;
+    List<Record> records;
+    
+    Map<String, Object> custom;
+}
+
+class Update {
+    Set<Column> columns;
+}
\ No newline at end of file
Added: branches/experimental/tests/data/emails-json.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/emails-json.php    Thu Oct 23 07:07:20
2008
@@ -0,0 +1,5 @@
+<?php
+include("emails.php");
+header("Content-Type: text/javascript");
+echo json_encode($result);
+?>
\ No newline at end of file
Added: branches/experimental/tests/data/emails-xml.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/emails-xml.php    Thu Oct 23 07:07:20 2008
@@ -0,0 +1,18 @@
+<?php
+include("emails.php");
+header("Content-Type: text/xml");
+$xml = new XMLWriter();
+$xml->openMemory();
+$xml->startDocument("1.0", "UTF-8");
+$xml->startElement("addressbook");
+$xml->writeAttribute("total", $result["totalRecords"]);
+foreach($result["records"] as $record) {
+    $xml->startElement("address");
+    $xml->writeElement("name", $record[0]);
+    $xml->writeElement("email", $record[1]);
+    $xml->endElement();
+}
+$xml->endElement();
+$xml->endDocument();
+echo $xml->flush();
+?>
\ No newline at end of file
Added: branches/experimental/tests/data/emails.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/emails.php    Thu Oct 23 07:07:20 2008
@@ -0,0 +1,27 @@
+<?php
+include("txtdb/txt-db-api.php");
+
+$db = new Database(ROOT_DATABASE);
+
+$offset = $_REQUEST["start"];
+$limit = $_REQUEST["limit"];
+$sort = $_REQUEST["sortColumn"];
+$sortDirection = $_REQUEST["sortDirection"];
+
+$totalSet = $db->executeQuery("select * from addressbook");
+// do not try at home, sql-injection vulnerable
+$resultSet = $db->executeQuery("select * from addressbook order by $sort
$sortDirection limit $offset, $limit");
+
+$records = array();
+while($resultSet->next()) {
+    array_push($records, array($resultSet->getCurrentValueByName("name"),
$resultSet->getCurrentValueByName("email")));
+}
+$result = array(
+    "totalRecords" => $totalSet->getRowCount(),
+    "columns" => array(
+        array("id" => "name", "label" => "Name", "width" => 125),
+        array("id" => "email", "label" => "Address", "width" => 250)
+    ),
+    "records" => $records
+);
+?>
\ No newline at end of file
Added: branches/experimental/tests/data/employees-json.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/employees-json.php    Thu Oct 23 07:07:20
2008
@@ -0,0 +1,43 @@
+<?php
+include("txtdb/txt-db-api.php");
+
+$db = new Database(ROOT_DATABASE);
+
+$offset = $_REQUEST["start"];
+$limit = $_REQUEST["limit"];
+$sort = $_REQUEST["sortColumn"];
+$sortDirection = $_REQUEST["sortDirection"];
+
+$totalSet = $db->executeQuery("select * from employees");
+// do not try at home, sql-injection vulnerable
+$resultSet = $db->executeQuery("select * from employees order by $sort
$sortDirection limit $offset, $limit");
+
+$records = array();
+while($resultSet->next()) {
+    array_push($records, array(
+        $resultSet->getCurrentValueByName("id"),
+        $resultSet->getCurrentValueByName("firstname"),
+        $resultSet->getCurrentValueByName("lastname"),
+        $resultSet->getCurrentValueByName("salary"),
+        $resultSet->getCurrentValueByName("city"),
+        $resultSet->getCurrentValueByName("department"),
+        $resultSet->getCurrentValueByName("firstworkday")
+    ));
+}
+
+$result = array(
+    "totalRecords" => $totalSet->getRowCount(),
+    "columns" => array(
+        array("id" => "id", "label" => "ID", "width" => 75),
+        array("id" => "firstname", "label" => "Firstname", "width" => 125),
+        array("id" => "lastname", "label" => "Lastname", "width" => 125),
+        array("id" => "salary", "label" => "Salary", "width" => 125),
+        array("id" => "city", "label" => "City", "width" => 150),
+        array("id" => "department", "label" => "Department", "width" => 150),
+        array("id" => "firstworkday", "label" => "Employed since", "width" =>
125)
+    ),
+    "records" => $records
+);
+header("Content-Type: text/javascript");
+echo json_encode($result);
+?>
\ No newline at end of file
Added: branches/experimental/tests/data/txtdb/addressbook.txt
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/txtdb/addressbook.txt    Thu Oct 23
07:07:20 2008
@@ -0,0 +1,13 @@
+id#name#email
+inc#str#str
+##
+1#Peter Pan#peter@pan.de
+2#Molly#molly@yahoo.com
+3#Forneria Marconi#live@japan.jp
+4#Master Sync#205bw@samsung.com
+5#Dr. Tech de Log#g15@logitech.com
+6#Don Corleone#don@vegas.com
+7#Mc Chick#info@donalds.org
+8#Donnie Darko#dd@timeshift.info
+9#Quake The Net#webmaster@quakenet.org
+10#Dr. Write#write@writable.com
\ No newline at end of file
Added: branches/experimental/tests/data/txtdb/const.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/txtdb/const.php    Thu Oct 23 07:07:20
2008
@@ -0,0 +1,112 @@
+<?php
+/**********************************************************************
+                         Php Textfile DB API
+                        Copyright 2005 by c-worker.ch
+                         http://www.c-worker.ch
+***********************************************************************/
+/**********************************************************************
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+/***********************************
+             User Settings
+************************************/
+
+$DEBUG=0;                 // 0=Debug disabled, 1=Debug enabled
+$LIKE_CASE_SENSITIVE=0; // 0=LIKE is case insensitive, 1=LIKE is case
sensitive
+$ORDER_CASE_SENSITIVE=0;    // 0=ORDER BY is case insensitive, 1=ORDER BY is
case sensitive
+$ASSUMED_RECORD_SIZE=30; // Set this to the average size of one record,
if in doubt
+ // leave the default value. DON'T set it to
<1! int's only!
+$PRINT_ERRORS=1;            // 0 = Errors are NOT displayed, 1 = Errors are
displayed
+$PRINT_WARNINGS=0;            // 0 = Warnings are NOT displayed, 1 = Warnings are
displayed
+
+
+
+/***********************************
+             Constants
+************************************/
+// Don't change them, expect you know
+// what you do!
+
+// Define User Settings
+define("LIKE_CASE_SENSITIVE",$LIKE_CASE_SENSITIVE);
+define("ORDER_CASE_SENSITIVE",$ORDER_CASE_SENSITIVE);
+define("TXTDBAPI_DEBUG",$DEBUG);
+
+// Even more Debug Infos ?
+define("TXTDBAPI_VERBOSE_DEBUG",0);
+
+// This constant doesn't limit the max size of a record it's only the
assmued size
+// of a record when a table is read for appending. If not a whole record is
+// contained in ASSUMED_RECORD_SIZE bytes, the the number of bytes read
+// is increased until a whole record was read. Choosing this value wisely
may
+// result in a better INSERT performance
+define("ASSUMED_RECORD_SIZE",$ASSUMED_RECORD_SIZE);
+
+define("PRINT_ERRORS",$PRINT_ERRORS);
+define("PRINT_WARNINGS",$PRINT_WARNINGS);
+
+// Version
+define("TXTDBAPI_VERSION","0.3.1-Beta-01");
+
+// General
+define("NOT_FOUND",-1);
+
+// File parsing
+define("COLUMN_SEPARATOR_CHAR",'#');    // Char which seperates the columns
in the table file
+                                        // This MUST be a sigle character and NOR a string
+define("TABLE_FILE_ESCAPE_CHAR",'%');     // Char to Escape
COLUMN_SEPARATOR_CHAR in the Table Files
+define("TABLE_FILE_OPEN_MODE",'b');     // "b" or ""
+
+// Timeouts
+define("OPEN_TIMEOUT",10);         // Timeout in seconds to try opening a still
locked Table
+define("LOCK_TIMEOUT",10);         // Timeout in seconds to try locking a still
locked Table
+define("LOCKFILE_TIMEOUT",30);     // Timeout for the maximum time a lockfile
can exist
+
+// Predefined Databases
+define("ROOT_DATABASE","");
+
+// Order Types
+define("ORDER_ASC",1);
+define("ORDER_DESC",2);
+
+// Join Types
+define("JOIN_INNER",1);
+define("JOIN_LEFT",2);
+define("JOIN_RIGHT",3);
+
+// Row Flags
+define("FLAG_KEEP",0x1);
+
+// Column Types
+define("COL_TYPE_INC","inc");
+define("COL_TYPE_INT","int");
+define("COL_TYPE_STRING","str");
+
+// Column Function Types
+define("COL_FUNC_TYPE_SINGLEREC",1);
+define("COL_FUNC_TYPE_GROUPING",2);
+
+// File Extensions
+define("TABLE_FILE_EXT",".txt");
+define("LOCK_FILE_EXT",".lock");
+
+
+?>
Added: branches/experimental/tests/data/txtdb/database.php
==============================================================================
--- (empty file)
+++ branches/experimental/tests/data/txtdb/database.php    Thu Oct 23 07:07:20
2008
@@ -0,0 +1,1136 @@
+<?php
+/**********************************************************************
+                         Php Textfile DB API
+                        Copyright 2005 by c-worker.ch
+                         http://www.c-worker.ch
+***********************************************************************/
+/**********************************************************************
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+***********************************************************************/
+
+include_once(API_HOME_DIR . "const.php");
+include_once(API_HOME_DIR . "util.php");
+include_once(API_HOME_DIR . "resultset.php");
+include_once(API_HOME_DIR . "sql.php");
+include_once(API_HOME_DIR . "expression.php");
+
+/**********************************************************************
+                            Database
+***********************************************************************/
+
+// Represents a Database and has functions to execute Sql-Queries on it
+class Database {
+ var $dbFolder;
+ var $lastInsertId=0;
+
+ var $lastErrorMsgs=array();
+
+     /***********************************
+                 Constructor
+    ************************************/
+    
+ function Database($dbFolder="defaultDb/") {          
+     $this->dbFolder= DB_DIR . $dbFolder;
+     if(last_char($this->dbFolder) != "/")
+         $this->dbFolder .= "/";
+ }
+
+
+ /***********************************
+             Insert Id Functions
+    ************************************/
+    function updateLastInsertId($resultSet) {
+        $resultSet->end();
+        for($i=0;$i<count($resultSet->colTypes);++$i) {
+            if($resultSet->colTypes[$i]==COL_TYPE_INC) {
+                $this->lastInsertId=$resultSet->getCurrentValueByNr($i);
+                debug_print("Setting lastInsertId to " . $this->lastInsertId );
+                return;
+            }
+        }
+ // if no inc column exists set lastInsertId to 0
+ $this->lastInsertId=0;
+ debug_print("Setting lastInsertId to " . $this->lastInsertId );
+ }
+
+    function getLastInsertId() {
+        return $this->lastInsertId;
+    }    
+    
+    /***********************************
+         Table open/close Functions
+    ************************************/
+    
+    // Does open a Table for writing
+    function openTableWrite($tableName) {
+        debug_print("openTableWrite
");
+        $filename=$this->dbFolder . $tableName . TABLE_FILE_EXT;
+        
+        $fp=fopen ($filename, "r+".TABLE_FILE_OPEN_MODE);
+        if (!$fp) return 0;
+        
+        while(!flock($fp, LOCK_EX)) {
+            usleep(50);
+        }
+
+        return $fp;
+    }
+    
+    // same rules as for openTableWrite()
+    // does open a table for appending
+    function openTableAppend($tableName) {
+        debug_print("openTableAppend
");
+        $filename=$this->dbFolder . $tableName . TABLE_FILE_EXT;
+
+        $fp=fopen ($filename, "a".TABLE_FILE_OPEN_MODE);
+        if (!$fp) return 0;
+        
+        while(!flock($fp, LOCK_EX)) {
+            usleep(50);
+        }
+
+        return $fp;
+    }
+        
+    // Opens a Table for reading
+    // This function is used by SELECT
+    // returns a FilePointer or false
+    function openTableRead($tableName) {
+        debug_print("openTableRead
");
+        $filename=$this->dbFolder . $tableName . TABLE_FILE_EXT;
+     debug_print("Table $tableName opened (READ)
");
+
+        if(!file_exists($filename)) return 0;
+
+        $fp=fopen ($filename, "r".TABLE_FILE_OPEN_MODE);
+        if (!$fp) return 0;
+        
+        while(!flock($fp, LOCK_SH)) {
+            usleep(50);
+        }
+
+        return $fp;
+    }
+    
+    // Closes a Table
+    function closeTable($fp) {
+        debug_print("Table $fp closed
");
+        while(!flock($fp, LOCK_UN)) {
+            usleep(50);
+        }
+        return fclose($fp);        
+    }
+    
+    
+    /***********************************
+         Table read/write Functions
+    ************************************/
+    
+    // Reads a Table into a ResultSet
+    // Returns a ResultSet or null (the function opens an closes the file
itself)
+ function readTable($tableName) {
+     debug_print("readTable
");
+     $parser= new ResultSetParser();
+     if(!($fd=$this->openTableRead($tableName))) {
+         print_error_msg("readTable(): Cannot open Table $tableName");
+         return null;
+     }
+     $rs=$parser->parseResultSetFromFile($fd);
+     $this->closeTable($fd);
+     return $rs;
+ }
+
+ // Reads a Table into a ResultSet
+ // But only the column names and types + the last record
+ // thats usefull for appending record
+ function readTableForAppend($tableName) {
+     debug_print("readTableForAppend
");
+     $parser= new ResultSetParser();
+     if(!($fd=$this->openTableRead($tableName))) {
+         print_error_msg("readTableForAppend(): Cannot open Table
$tableName");
+         return null;
+     }
+     $rs=$parser->parseResultSetFromFileForAppend($fd);
+     $this->closeTable($fd);
+     return $rs;
+ }
+
+
+ // writes the table by using the FilePointer $fd
+ // $fd has to be opened an closed by the caller
+ function writeTable($fd, $resultSet) {
+     debug_print("writeTable
");
+     $parser= new ResultSetParser();
+     return $parser->parseResultSetIntoFile($fd, $resultSet);
+ }
+
+ // appends to the table by using the FilePointer $fd
+ // $fd has to be opened an closed by the caller
+ function appendToTable($fd, $resultSet,$recordCount) {
+     debug_print("appendToTable
");
+     $parser= new ResultSetParser();
+     while($resultSet->getRowCount()>$recordCount) {
+         $resultSet->reset();
+         $resultSet->next();
+         $resultSet->deleteCurrentRow();
+     }
+     return $parser->parseResultSetIntoFileAppend($fd, $resultSet);
+ }
+
+
+
+    
+    /***********************************
+             Query dispatcher
+    ************************************/
+    
+    // $sql_query_str is an unparsed SQL Query String
+    // Return Values:
+    // SELECT Queries: Returns a ResultSet Object or false
+    // CREATE TABLE: Returns true or false
+    // All other types: Returns the number of rows affected
+    function executeQuery($sql_query_str) {
+        set_error_handler("txtdbapi_error_handler");
+        txtdbapi_clear_errors();
+        
+        debug_printb("[executeQuery] Query: $sql_query_str
");
+        
+        // Parse Query
+        $start=getmicrotime();
+        $sqlParser=new SqlParser($sql_query_str);
+         $sqlQuery=$sqlParser->parseSqlQuery();
+         debug_print("parseSqlQuery: " . (getmicrotime() - $start) . " seconds
elapsed
");
+
+
+
+         // free $sqlParser
+         unset($sqlParser);
+         $sqlParser="";
+         
+         // Test Query
+         if((!$sqlQuery) || (!$sqlQuery->test())) {
+ &nbs