[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 01/05: new tool for developing
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 01/05: new tool for developing |
Date: |
Tue, 02 Feb 2016 14:36:17 +0000 |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 5058c952e7c3b308dc6480adbf7dc0f7af6e12e9
Author: Dany De Bontridder <address@hidden>
Date: Sat Jan 30 16:25:15 2016 +0100
new tool for developing
---
dev/SQL/index.php | 82 +++++++++++++++++++++++++++++++++++++++
dev/SQL/table_sql.class.php | 61 +++++++++++++++++++++++++++++
dev/SQL/template/script_sql.php | 65 +++++++++++++++++++++++++++++++
3 files changed, 208 insertions(+), 0 deletions(-)
diff --git a/dev/SQL/index.php b/dev/SQL/index.php
new file mode 100644
index 0000000..e3c24d2
--- /dev/null
+++ b/dev/SQL/index.php
@@ -0,0 +1,82 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+require_once '../../include/constant.php';
+const REPOSITORY_DB=1;
+const ACCOUNT_DB=2;
+
+require NOALYSS_INCLUDE."/lib/class_database.php";
+require NOALYSS_INCLUDE."/lib/class_iselect.php";
+
+require './table_sql.class.php';
+
+// Show a db connection
+$gDossier=HtmlInput::default_value_request('gDossier',-1);
+$select = new ISelect('gDossier');
+$select->row=20;
+$acc=new Database();
+
+$a_dossier=$acc->make_array("select dos_id,dos_id::text||' '||dos_name from
ac_dossier order by dos_id");
+$a_dossier[]=array('value'=>0,'label'=>'Account_Repository');
+$select->value=$a_dossier;
+$select->selected = $gDossier;
+
+//////////////////////////////////////////////////////////////////////////////
+// If no db is selected then propose one
+//////////////////////////////////////////////////////////////////////////////
+if ($gDossier==-1) {
+?>
+<form method="get">
+ <?php echo $select->input();?>
+ <?php echo HtmlInput::submit("choose_db", "Valider");?>
+</form>
+<?php
+return;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+// If db IS selected
+//////////////////////////////////////////////////////////////////////////////
+/**
+ * Connect to the selected DB
+ */
+ if ( $gDossier==0)
+ $cn=new Database();
+ else
+ $cn=new Database($gDossier,'dos');
+
+/**
+ * Display list of all tables and view from selected DB
+ */
+$table_sql = "select schemaname ||','||tablename,tablename||','||schemaname
from pg_tables where schemaname not in ('pg_catalog','information_schema')
order by 1";
+
+$select_table = new ISelect('table');
+$select_table->row=20;
+$select_table->value=$cn->make_array($table_sql);
+$select_table->selected = HtmlInput::default_value_request("table", "");
+?>
+ <form method="get">
+ Choisissez une table
+ <?php echo $select_table->input();?>
+ <?php echo HtmlInput::hidden("gDossier", $gDossier);?>,
+ <?php echo HtmlInput::submit("choose_table", "Valider")?>
+ <a href="?"> Autre</a>
+</form>
+<?php
+///////////////////////////////////////////////////////////////////////////////
+// if a table is select , generate file
+//////////////////////////////////////////////////////////////////////////////
+$table=HtmlInput::default_value_request("table", "");
+if ( $table != "") {
+ $table_sql=new Table_SQL($cn,$table);
+ $table_sql->create_class();
+ echo '<pre>';
+ $table_sql->send();
+ echo '</pre>';
+}
+
+?>
diff --git a/dev/SQL/table_sql.class.php b/dev/SQL/table_sql.class.php
new file mode 100644
index 0000000..19ac2cc
--- /dev/null
+++ b/dev/SQL/table_sql.class.php
@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of Table_SQL
+ *
+ * @author dany
+ */
+class Table_SQL {
+ private $table_name;
+ private $schema_name;
+ private $script;
+ private $db;
+ function __construct(Database $cn,$p_schematable) {
+ list($this->schema_name,$this->table_name)=
explode(",",$p_schematable);
+ $this->db=$cn;
+ }
+ /**
+ * Must create a Object to handle the SQL object
+ */
+ function create_class()
+ {
+ $this->script="";
+ $columns=$this->db->get_array("
+ select column_name,data_type,is_nullable from
information_schema.columns
+ where
+ table_name=$1
+ and
+ table_schema=$2 order by ordinal_position",
+ array($this->table_name,$this->schema_name)
+ );
+ $apk=$this->db->get_array("
+ select column_name from information_schema.constraint_column_usage
where constraint_name = (select constraint_name from
+information_schema.table_constraints
+ where
+ table_name = $1
+ and table_schema=$2
+ and constraint_type='PRIMARY KEY')
+;
+"
+ ,array($this->table_name,$this->schema_name));
+ if ( count($apk) > 1 ) {
+ $this->pk="pk composé";
+ } else {
+ $this->pk=$apk[0]['column_name'];
+ }
+ ob_start();
+ include 'template/script_sql.php';
+ $this->script= ob_get_contents();
+ ob_clean();
+ }
+ function send()
+ {
+ echo $this->script;
+ }
+}
diff --git a/dev/SQL/template/script_sql.php b/dev/SQL/template/script_sql.php
new file mode 100644
index 0000000..3979fb0
--- /dev/null
+++ b/dev/SQL/template/script_sql.php
@@ -0,0 +1,65 @@
+
+
+/**
+ * Autogenerated file
+ */
+/**
+ * <?php echo $this->table_name."_sql.class.php"."\n"; ?>
+ *
+ address@hidden
+ address@hidden abstract of the table <?php echo
$this->schema_name.".".$this->table_name?>
+ */
+class <?php echo ucwords($this->table_name)."_SQL";?> extends SQL
+{
+
+function __construct($p_id=-1)
+ {
+ $this->table = "<?php echo $this->schema_name.".".$this->table_name?>";
+ $this->primary_key = "<?php echo $this->pk?>";
+/*
+ * List of columns
+ */
+ $this->name=array(
+ <?php
+ $sep="";
+ for ($i=0;$i < count($columns);$i++):
+ print "\t".
$sep.'"'.$columns[$i]['column_name'].'"'.'=>'.'"'.$columns[$i]['column_name'].'"';
+ $sep=",";
+ printf("\n");
+ endfor;
+?>
+ );
+/*
+ * Type of columns
+ */
+ $this->type = array(
+ <?php
+ $sep="";
+ for ($i=0;$i < count($columns);$i++):
+ $type=$columns[$i]['data_type'];
+ if ( in_array($columns[$i]['data_type'],
array('integer','numeric','bigint'))):
+ $type="numeric";
+ elseif (in_array($columns[$i]['data_type'],
array('character','character varying','text'))):
+ $type="text";
+ elseif (in_array($columns[$i]['data_type'], array('timestamp without
timezone','timestamp with timezone','date'))):
+ $type="date";
+ endif;
+ print "\t". $sep.'"'.$columns[$i]['column_name'].'"'.'=>'.'"'.$type.'"';
+ printf("\n");
+ $sep=",";
+ endfor;
+?> );
+
+
+ $this->default = array(
+ "<?php echo $this->pk?>" => "auto",
+ );
+
+ $this->date_format = "DD.MM.YYYY";
+ global $cn;
+
+ parent::__construct($cn,$p_id);
+ }
+
+
+}
\ No newline at end of file
- [Noalyss-commit] [noalyss] branch master updated (759dfab -> 12c15fb), Dany De Bontridder, 2016/02/02
- [Noalyss-commit] [noalyss] 02/05: new tool for developing, Dany De Bontridder, 2016/02/02
- [Noalyss-commit] [noalyss] 04/05: Add FIX_BROKEN_PDF in constant.php by default it is NO, Dany De Bontridder, 2016/02/02
- [Noalyss-commit] [noalyss] 03/05: Improve dev tool, Dany De Bontridder, 2016/02/02
- [Noalyss-commit] [noalyss] 05/05: Fix problem with PDF , the forced conversion to image and back to PDF doesnt work properly, it works better with ps2pdf and pdf2ps, Dany De Bontridder, 2016/02/02
- [Noalyss-commit] [noalyss] 01/05: new tool for developing,
Dany De Bontridder <=