This repository has been archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db2xml.php
116 lines (95 loc) · 3.31 KB
/
db2xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require_once('./sessionmanager.php');
startSession();
require_once ('./config/config.inc.php');
require_once('./smarty/libs/Smarty.class.php');
require_once('./dbtypeparser.php');
$smarty = new Smarty;
$smarty->template_dir = './templates';
$smarty->compile_dir = './smarty/demo/templates_c';
$smarty->config_dir = './smarty/demo/configs';
class MyObject{
public $fieldName;
public $fieldType;
public $fieldLenght;
public $canBeNull;
public $autoIncrement;
public $pk;
}
$selectedProject = $storegameContext;
//$selectedProject = $amandaContext;
try{
$selectedDatabase = $selectedProject->getDatabaseConnection();
$bdd = new PDO($selectedDatabase->getDSN(), $selectedDatabase->getUser(), $selectedDatabase->getPassword());
} catch (Exception $e) {
echo $e;
}
$directory = $selectedProject->getDataModelDirectory();
$statement = "SHOW TABLES";
$tables = $bdd->query($statement);
$smarty->registerObject('MyObject',new MyObject(),null,false);
while ($donnees = $tables->fetch())
{
$table = $donnees[0];
$smarty->assign("tableName", $table);
$statementGetFieldTable = "Select * from ".$table. ' LIMIT 1';
$fields = $bdd->query($statementGetFieldTable);
$field_name_array = array();
$i = 0;
while ($field = $fields->getColumnMeta($i++)) {
$field_name = $field['name'];
//$field_type = $field['native_type'];
//$field_lenght = $field['len'];
$fieldObject = new MyObject();
$fieldObject->fieldName = $field_name;
//$fieldObject->fieldType = $phpPDOTypes[$field_type];
//$fieldObject->fieldLenght = $field_lenght;
$field_name_array[$field_name] = $fieldObject;
}
$statementGetFieldTable = "SHOW COLUMNS from ".$table;
$fields = $bdd->query($statementGetFieldTable);
while ($field = $fields->fetch()) {
$field_name = $field['Field'];
$fieldObject = $field_name_array[$field_name];
$field_type = $field['Type'];
registerDBType($field_type);
$db_Type = $_SESSION["dbType"];
$fieldObject->fieldType = $db_Type->type;
$fieldObject->fieldLenght = $db_Type->length;
$canBeNull = $field['Null'];
if ($canBeNull == 'YES') {
$fieldObject->canBeNull = 'true';
} else {
$fieldObject->canBeNull = 'false';
}
$extra = $field['Extra'];
if (strpos($extra, 'auto_increment') === FALSE) {
$fieldObject->autoIncrement = 'false';
$pk = $field['Key'];
if (strpos($pk, 'PRI') === FALSE) {
$fieldObject->pk = 'false';
} else {
$fieldObject->pk = 'true';
}
} else {
$fieldObject->autoIncrement = 'true';
$fieldObject->pk = 'true';
}
}
$smarty->assignByRef("fieldNameArray", $field_name_array);
$to_write = $smarty->fetch('datamodel.tpl');
$file_name = $directory.$table.".xml";
echo "Generating ".$file_name."</BR>";
$fh = fopen($file_name, "w+b") or die("Can't open file");
fwrite($fh, $to_write);
fclose($fh);
}
require_once("./utilities.php");
echo "Copying necessary datamodel.xsd</BR>";
copyemz("./config/datamodel.xsd", $directory."/datamodel.xsd");
echo "Done";
//endSession();
?>
<FORM method=post action="./dbtoobject.php">
<INPUT type="submit" value="Generate pojo">
</form>