Skip to content

Commit

Permalink
initial code from release 2.3.1
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : svn%3Ab267cdba-c1da-11dd-874b-8bacd04a0a74/trunk%402
  • Loading branch information
ondrej.zara committed Dec 4, 2008
1 parent 6bcb4d2 commit 3e17dc9
Show file tree
Hide file tree
Showing 43 changed files with 5,492 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/php-blank/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
header("HTTP/1.0 501 Not Implemented");
?>
30 changes: 30 additions & 0 deletions backend/php-file/data/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?><sql><datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>
</group>

<group label="Character" color="rgb(255,200,200)">
<type label="Char" length="1" sql="CHAR" quote="'"/>
<type label="Varchar" length="1" sql="VARCHAR" quote="'"/>
<type label="Text" length="0" sql="MEDIUMTEXT" re="TEXT" quote="'"/>
<type label="Binary" length="1" sql="BINARY" quote="'"/>
<type label="Varbinary" length="1" sql="VARBINARY" quote="'"/>
<type label="BLOB" length="0" sql="BLOB" re="BLOB" quote="'"/>
</group>

<group label="Date &amp; Time" color="rgb(200,255,200)">
<type label="Date" length="0" sql="DATE" quote="'"/>
<type label="Time" length="0" sql="TIME" quote="'"/>
<type label="Datetime" length="0" sql="DATETIME" quote="'"/>
<type label="Year" length="0" sql="YEAR" quote=""/>
<type label="Timestamp" length="0" sql="TIMESTAMP" quote="'"/>
</group>

<group label="Miscellaneous" color="rgb(200,200,255)">
<type label="ENUM" length="1" sql="ENUM" quote=""/>
<type label="SET" length="1" sql="SET" quote=""/>
</group>
</datatypes><table x="50" y="50" name="Producer"><row name="id" null="0" autoincrement="1"><datatype>INTEGER</datatype></row><row name="name" null="1" autoincrement="0"><datatype>VARCHAR(100)</datatype><default>NULL</default></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="574" y="66" name="Consumer"><row name="id" null="0" autoincrement="1"><datatype>INTEGER</datatype></row><row name="name" null="1" autoincrement="0"><datatype>VARCHAR(100)</datatype><default>NULL</default></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="195" y="333" name="Product"><row name="id" null="0" autoincrement="1"><datatype>INTEGER</datatype></row><row name="id_Producer" null="0" autoincrement="1"><datatype>INTEGER</datatype><relation table="Producer" row="id" /></row><row name="name" null="1" autoincrement="0"><datatype>VARCHAR(100)</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table><table x="383" y="227" name="Garbage"><row name="id" null="0" autoincrement="1"><datatype>INTEGER</datatype></row><row name="id_Product" null="0" autoincrement="1"><datatype>INTEGER</datatype><relation table="Product" row="id" /></row><row name="id_Consumer" null="0" autoincrement="1"><datatype>INTEGER</datatype><relation table="Consumer" row="id" /></row><row name="consumed" null="0" autoincrement="0"><datatype>TIMESTAMP</datatype></row><key type="PRIMARY" name=""><part>id</part></key></table></sql>
35 changes: 35 additions & 0 deletions backend/php-file/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
$a = (isset($_GET["action"]) ? $_GET["action"] : false);
switch ($a) {
case "list":
$files = glob("data/*");
foreach ($files as $file) {
$name = basename($file);
echo $name."\n";
}
break;
case "save":
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$keyword = "data/".basename($keyword);
$f = fopen($keyword, "w");
$data = file_get_contents("php://input");
if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
$data = stripslashes($data);
}
fwrite($f, $data);
fclose($f);
header("HTTP/1.0 201 Created");
break;
case "load":
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$keyword = "data/".basename($keyword);
if (!file_exists($keyword)) {
header("HTTP/1.0 404 Not Found");
} else {
header("Content-type: text/xml");
echo file_get_contents($keyword);
}
break;
default: header("HTTP/1.0 501 Not Implemented");
}
?>
8 changes: 8 additions & 0 deletions backend/php-mysql/database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS `wwwsqldesigner`;

CREATE TABLE `wwwsqldesigner` (
`keyword` varchar(30) NOT NULL default '',
`data` text,
`dt` timestamp,
PRIMARY KEY (`keyword`)
);
192 changes: 192 additions & 0 deletions backend/php-mysql/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php
function setup_saveloadlist() {
define("SERVER","localhost");
define("USER","");
define("PASSWORD","");
define("DB","home");
define("TABLE","wwwsqldesigner");
}
function setup_import() {
define("SERVER","tv1.dev");
define("USER","tvprogram");
define("PASSWORD","xxx");
define("DB","information_schema");
}
function connect() {
$conn = mysql_connect(SERVER,USER,PASSWORD);
if (!$conn) return false;
$res = mysql_select_db(DB);
if (!$res) return false;
return true;
}

function import() {
$db = (isset($_GET["database"]) ? $_GET["database"] : "information_schema");
$db = mysql_real_escape_string($db);
$xml = "";

$arr = array();
@ $datatypes = file("../../db/mysql/datatypes.xml");
$arr[] = $datatypes[0];
$arr[] = '<sql db="mysql">';
for ($i=1;$i<count($datatypes);$i++) {
$arr[] = $datatypes[$i];
}

$result = mysql_query("SELECT * FROM TABLES WHERE TABLE_SCHEMA = '".$db."'");
while ($row = mysql_fetch_array($result)) {
$table = $row["TABLE_NAME"];
$xml .= '<table name="'.$table.'">';
$comment = (isset($row["TABLE_COMMENT"]) ? $row["TABLE_COMMENT"] : "");
if ($comment) { $xml .= '<comment>'.$comment.'</comment>'; }

$q = "SELECT * FROM COLUMNS WHERE TABLE_NAME = '".$table."' AND TABLE_SCHEMA = '".$db."'";
$result2 = mysql_query($q);
while ($row = mysql_fetch_array($result2)) {
$name = $row["COLUMN_NAME"];
$type = $row["COLUMN_TYPE"];
$comment = (isset($row["COLUMN_COMMENT"]) ? $row["COLUMN_COMMENT"] : "");
$null = ($row["IS_NULLABLE"] == "YES" ? "0" : "1");
$def = $row["COLUMN_DEFAULT"];
$ai = (preg_match("/auto_increment/i",$row["EXTRA"]) ? "1" : "0");
if ($def == "NULL") { $def = ""; }
$xml .= '<row name="'.$name.'" null="'.$null.'" autoincrement="'.$ai.'">';
$xml .= '<datatype>'.strtoupper($type).'</datatype>';
$xml .= '<default>'.$def.'</default>';
if ($comment) { $xml .= '<comment>'.$comment.'</comment>'; }

/* fk constraints */
$q = "SELECT
REFERENCED_TABLE_NAME AS 'table', REFERENCED_COLUMN_NAME AS 'column'
FROM KEY_COLUMN_USAGE k
LEFT JOIN TABLE_CONSTRAINTS c
ON k.CONSTRAINT_NAME = c.CONSTRAINT_NAME
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
AND c.TABLE_SCHEMA = '".$db."' AND c.TABLE_NAME = '".$table."'
AND k.COLUMN_NAME = '".$name."'";
$result3 = mysql_query($q);

while ($row = mysql_fetch_array($result3)) {
$xml .= '<relation table="'.$row["table"].'" row="'.$row["column"].'" />';
}

$xml .= '</row>';
}

/* keys */
$q = "SELECT * FROM STATISTICS WHERE TABLE_NAME = '".$table."' AND TABLE_SCHEMA = '".$db."' ORDER BY SEQ_IN_INDEX ASC";
$result2 = mysql_query($q);
$idx = array();

while ($row = mysql_fetch_array($result2)) {
$name = $row["INDEX_NAME"];
if (array_key_exists($name, $idx)) {
$obj = $idx[$name];
} else {
$type = $row["INDEX_TYPE"];
$t = "INDEX";
if ($type == "FULLTEXT") { $t = $type; }
if ($row["NON_UNIQUE"] == "0") { $t = "UNIQUE"; }
if ($name == "PRIMARY") { $t = "PRIMARY"; }

$obj = array(
"columns" => array(),
"type" => $t
);
}

$obj["columns"][] = $row["COLUMN_NAME"];
$idx[$name] = $obj;
}

foreach ($idx as $name=>$obj) {
$xml .= '<key name="'.$name.'" type="'.$obj["type"].'">';
for ($i=0;$i<count($obj["columns"]);$i++) {
$col = $obj["columns"][$i];
$xml .= '<part>'.$col.'</part>';
}
$xml .= '</key>';
}
$xml .= "</table>";
}
$arr[] = $xml;
$arr[] = '</sql>';
return implode("\n",$arr);
}

$a = (isset($_GET["action"]) ? $_GET["action"] : false);
switch ($a) {
case "list":
setup_saveloadlist();
if (!connect()) {
header("HTTP/1.0 503 Service Unavailable");
break;
}
$result = mysql_query("SELECT keyword FROM ".TABLE." ORDER BY dt DESC");
while ($row = mysql_fetch_assoc($result)) {
echo $row["keyword"]."\n";
}
break;
case "save":
setup_saveloadlist();
if (!connect()) {
header("HTTP/1.0 503 Service Unavailable");
break;
}
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$keyword = mysql_real_escape_string($keyword);
$data = file_get_contents("php://input");
if (get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
$r = mysql_query("SELECT * FROM ".TABLE." WHERE keyword = '".$keyword."'");
if (mysql_num_rows($r) > 0) {
$res = mysql_query("UPDATE ".TABLE." SET data = '".$data."' WHERE keyword = '".$keyword."'");
} else {
$res = mysql_query("INSERT INTO ".TABLE." (keyword, data) VALUES ('".$keyword."', '".$data."')");
}
if (!$res) {
header("HTTP/1.0 500 Internal Server Error");
} else {
header("HTTP/1.0 201 Created");
}
break;
case "load":
setup_saveloadlist();
if (!connect()) {
header("HTTP/1.0 503 Service Unavailable");
break;
}
$keyword = (isset($_GET["keyword"]) ? $_GET["keyword"] : "");
$keyword = mysql_real_escape_string($keyword);
$result = mysql_query("SELECT `data` FROM ".TABLE." WHERE keyword = '".$keyword."'");
$row = mysql_fetch_assoc($result);
if (!$row) {
header("HTTP/1.0 404 Not Found");
} else {
header("Content-type: text/xml");
echo $row["data"];
}
break;
case "import":
setup_import();
if (!connect()) {
header("HTTP/1.0 503 Service Unavailable");
break;
}

header("Content-type: text/xml");
echo import();
break;
default: header("HTTP/1.0 501 Not Implemented");
}


/*
list: 501/200
load: 501/200/404
save: 501/201
import: 501/200
*/
?>
103 changes: 103 additions & 0 deletions backend/php-sqlite/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
function setup_saveloadlist() {
define( "FILE" , "wwwsqldesigner.sqlite" );
define( "TABLE" , "wwwsqldesigner" );
}
function setup_import() {
header( 'HTTP/1.0 501 Not Implemented' );
die;
}
function connect() {
if( !file_exists( FILE ) ) $initReq = true;
$GLOBALS['sqlConnect'] = sqlite_open( FILE , 0666 );
if( !$GLOBALS['sqlConnect'] ) return false;
if( $initReq ) {
$initSQL = "CREATE TABLE wwwsqldesigner (
keyword varchar(30) NOT NULL default '',
data TEXT ,
dt DATETIME DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ( keyword )
);";
$res = sqlite_exec( $initSQL , $GLOBALS['sqlConnect'] );
return $res;
}
return true;
}
function import() {
header( 'HTTP/1.0 501 Not Implemented' );
}

$a = (isset($_GET["action"]) ? $_GET["action"] : false);
switch( $a ) {
case 'list' :
setup_saveloadlist();
if( !connect() ) {
header( 'HTTP/1.0 503 Service Unavailable' );
break;
}
$result = sqlite_query( "SELECT keyword FROM ".TABLE." ORDER BY dt DESC" , $GLOBALS['sqlConnect'] );
if( sqlite_num_rows( $result )>0 ) {
while( $row = sqlite_fetch_array( $result ) ) {
echo $row['keyword']."\n";
}
} else {
echo "--No Designs Saved";
}
break;
case 'save' :
setup_saveloadlist();
if( !connect() ) {
header( 'HTTP/1.0 503 Service Unavailable' );
break;
}
$keyword = ( isset( $_GET['keyword'] ) ? $_GET['keyword'] : '' );
$keyword = sqlite_escape_string( $keyword );
$data = file_get_contents( "php://input" );
if( get_magic_quotes_gpc()
|| get_magic_quotes_runtime() ) {
$data = stripslashes( $data );
}
$data = sqlite_escape_string( $data );
$r = sqlite_query( "SELECT * FROM ".TABLE." WHERE keyword = '$keyword'" , $GLOBALS['sqlConnect'] );
if( sqlite_num_rows($r)>0 ) {
$res = sqlite_query( "UPDATE ".TABLE." SET data = '$data' WHERE keyword = '$keyword'" , $GLOBALS['sqlConnect'] );
} else {
$res = sqlite_query( "INSERT INTO ".TABLE." (keyword, data) VALUES ('$keyword', '$data')" , $GLOBALS['sqlConnect'] );
}
if( !$res ) {
header( 'HTTP/1.0 500 Internal Server Error' );
} else {
header( 'HTTP/1.0 201 Created' );
}
break;
case 'load' :
setup_saveloadlist();
if ( !connect() ) {
header( 'HTTP/1.0 503 Service Unavailable' );
break;
}
$keyword = ( isset( $_GET['keyword'] ) ? $_GET['keyword'] : '' );
$keyword = sqlite_escape_string( $keyword );
$result = sqlite_query( "SELECT `data` FROM ".TABLE." WHERE keyword = '$keyword'" , $GLOBALS['sqlConnect'] );
$row = sqlite_fetch_array( $result );
if( !$row ) {
header( 'HTTP/1.0 404 Not Found' );
} else {
header( 'Content-type: text/xml' );
echo $row['data'];
}
break;
case 'import' :
setup_import();
default:
header( 'HTTP/1.0 501 Not Implemented' );
}


/*
list: 501/200
load: 501/200/404
save: 501/201
import: 501/200
*/
?>
Binary file added backend/php-sqlite/wwwsqldesigner.sqlite
Binary file not shown.
Loading

0 comments on commit 3e17dc9

Please sign in to comment.