added SQLite DBMS support and sortTables algorythm

Esse commit está contido em:
Felipe Nascimento de Moura
2011-03-31 22:46:48 -03:00
commit 53dd54153a
6 arquivos alterados com 93 adições e 20 exclusões
Arquivo binário não exibido.

Antes

Largura:  |  Altura:  |  Tamanho: 1.2 KiB

+10 -1
Ver Arquivo
@@ -13,6 +13,15 @@
font-weight:bold;
color: blue;
}
value
{
color: #c00;
font-style:italic;
}
element
{
font-style:italic;
}
object
{
color: blue;
@@ -34,7 +43,7 @@
<input type='button' value='commit project demo_en' onclick="commit()"/>
<input type='button' value='show queries' onclick="showQueries()"/>
<input type='button' value='logoff' onclick="logoff()"/>
<pre><div id='result' style='border:dashed 1px #777;'></div></pre>
<pre><div id='result' style='border:solid 1px #777;'></div></pre>
</body>
<script>
function setLoading()
+11 -6
Ver Arquivo
@@ -14,12 +14,17 @@ class sqlite implements DBMS{
public function createDefault()
{
return "DEFAULT <defaultvalue>";
return "<object>DEFAULT</object> <value><defaultvalue></value>";
}
public function createReferences()
{
return "<object>REFERENCES</object> <element><referencetablename></element>(<element><referencecolumnname></element>)";
}
public function property()
{
return "<property><propertyname></property> <propertytype><propertysize> <propertydetails>";
return "<property><propertyname></property> <propertytype><propertysize> <propertydetails> <references>";
}
public function createOptionsCheck()
@@ -29,7 +34,7 @@ class sqlite implements DBMS{
public function notNullDefinition()
{
return "NOT NULL";
return "<object>NOT NULL</object>";
}
public function autoIncrementType()
@@ -39,7 +44,7 @@ class sqlite implements DBMS{
public function createUnique()
{
return "UNIQUE";
return "<object>UNIQUE</object>";
}
public function getHeader()
@@ -69,7 +74,7 @@ class sqlite implements DBMS{
public function createPrimaryKeys()
{
return "
<object>CONSTRAINT</object> <fkname> <object>PRIMARY KEY</object> (<propertienames>)
<object>CONSTRAINT</object> <element><fkname></element> <object>PRIMARY KEY</object> (<element><propertienames></element>)
";
}
@@ -83,7 +88,7 @@ class sqlite implements DBMS{
public function createAutoIncrement()
{
return "AUTO_INCREMENT";
return "<object>AUTO_INCREMENT</object>";
}
public function createTable()
+18 -3
Ver Arquivo
@@ -31,6 +31,7 @@ class Query {
const CONSTRAINT_NAME= '/<constraintname(\/)?>/';
const REF_TAB_NAME = '/<referencetablename(\/)?>/';
const REF_COL_NAME = '/<referencecolumnname(\/)?>/';
const REFERENCES = '/<references(\/)?>/';
const FK_NAME= '/<fkname(\/)?>/';
public $query= "";
public $closingQuery= Array();
@@ -72,8 +73,20 @@ class Query {
if($prop['required'])
$details[]= QueryFactory::getQueryString('notNullDefinition');
if($prop['ref_to_property'] && QueryFactory::$mustSort)
{
$tb= explode('.', $prop['ref_to_property']);
$col= $tb[1];
$tb= $tb[0];
$reference= QueryFactory::getQueryString('createReferences');
$reference= preg_replace(self::REF_TAB_NAME, $tb, $reference);
$reference= preg_replace(self::REF_COL_NAME, $col, $reference);
$details[]= $reference;
}
//
$prop['options']= JSON_decode($prop['options']);
if($prop['options'])
$prop['options']= JSON_decode($prop['options']);
if(sizeof($prop['options'])>0)
{
$optionsTplt= QueryFactory::getQueryString('createOptionsCheck');
@@ -90,7 +103,7 @@ class Query {
$options),
$optionsTplt);
}
//print_r($prop);
if($prop['unique_value'])
{
$details[]= QueryFactory::getQueryString('createUnique');
@@ -120,15 +133,17 @@ class Query {
}
if($prop['size'])
$propQuery= preg_replace(self::PROP_SIZE, "(".$prop['size'].")", $propQuery);
$propQuery= preg_replace(self::PROP_SIZE, "(<value>".$prop['size']."</value>)", $propQuery);
else
$propQuery= preg_replace(self::PROP_SIZE, "", $propQuery);
$propQuery= preg_replace(self::PROP_NAME, $prop['name'], $propQuery);
$propQuery= preg_replace(self::PROP_DETAILS,
$this->parseDetails($prop, $table),
$propQuery);
$propQuery= preg_replace(self::PROP_TYPE, $prop['type'], $propQuery);
$propQuery= preg_replace(self::REFERENCES, '', $propQuery);
$tmpQuery.= trim($propQuery).",\n ";
}
+47 -10
Ver Arquivo
@@ -14,32 +14,69 @@ namespace DQB;
abstract class TableSort {
public static $original= false;
public static $ordered= false;
public static $unordered= false;
public static $ordered= Array();
public static $unordered= Array();
public static $aux= false;
private static function tableRefsTo($table)
private static function tableRefsTo(&$table)
{
foreach($table['properties'] as $prop)
$ar= Array();
if(!isset($table['ref_to']))
{
if($prop['ref_to_property'])
foreach($table['properties'] as $prop)
{
return true;
if($prop['ref_to_property'])
{
$ref= explode('.', $prop['ref_to_property']);
$ar[]= $ref[0];
}
}
}
if(sizeof($ar) > 0)
{
$table['ref_to']= $ar;
return $ar;
}
}else
return $table['ref_to'];
return false;
}
private static function addToOrderedList($qrKey)
{
$qr= self::$unordered[$qrKey];
self::$ordered[$qr->table['name']]= $qr;
unset(self::$unordered[$qrKey]);
}
private static function isOrdered($qrKey)
{
$qr= self::$unordered[$qrKey];
foreach($qr->table['ref_to'] as $ref)
{
if(!isset(self::$ordered[$ref]))
return false;
}
return true;
}
private static function doSort()
{
foreach(self::$unordered as $k=>$query)
{
// if the table does not referres to anyone, it can
// be added to the ordered list
if(!self::tableRefsTo($query->table))
{
self::$ordered[]= $query;
unset(self::$unordered[$k]);
}// TODO: order the other tables
self::addToOrderedList($k);
}else{
if(self::isOrdered($k))
{
self::addToOrderedList($k);
}
}
}
if(sizeof(self::$unordered)>0)
self::doSort();
return self::$ordered;
}
+7
Ver Arquivo
@@ -7,6 +7,13 @@
/**
* Description of DBMS
* Possible tags for markup:
* object
* element
* value
* property
* keyword
* comment
*
* @author felipe
*/