Perform the file
create_config.py create the needed config file for create_phpclass create_phpclass is now able to support default value, related to empty string or 0 instead of a NULL value
This commit is contained in:
parent
129d2ffbd9
commit
734159bda6
2 changed files with 69 additions and 3 deletions
65
dev/manage-code/create-file/create_config.py
Executable file
65
dev/manage-code/create-file/create_config.py
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/python
|
||||
#-*- coding: utf-8 -*-
|
||||
#
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
import getopt
|
||||
import sys
|
||||
|
||||
try:
|
||||
opt,args=getopt.getopt(sys.argv[1:],'s:t:c:')
|
||||
if len (opt) == 0 :
|
||||
raise NameError ('option')
|
||||
schema='public'
|
||||
table=''
|
||||
connexion_string=''
|
||||
class_name="None"
|
||||
for o,a in opt:
|
||||
if o == '-s':
|
||||
schema=a
|
||||
elif o == '-t':
|
||||
table=a
|
||||
elif o == '-c':
|
||||
connexion_string=a
|
||||
|
||||
if table == '':
|
||||
raise NameError('table')
|
||||
except:
|
||||
print "Utilisation "+sys.argv[0]+" -s nom_du_schema -t nom de la table + c connexion string"
|
||||
print 'example -t jrnxc -c "dbname=xxx user=xx port=xx password=xxx"'
|
||||
sys.exit(-1)
|
||||
|
||||
cnx=psycopg2.connect (connexion_string)
|
||||
curs=cnx.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||
|
||||
curs.execute('''
|
||||
SELECT
|
||||
columns.column_name,columns.data_type,columns.column_default
|
||||
FROM
|
||||
information_schema.columns
|
||||
WHERE
|
||||
columns.table_schema=%s
|
||||
and columns.table_name=%s
|
||||
''',(schema,table))
|
||||
record=curs.fetchall()
|
||||
file_name=table+"_struct.txt"
|
||||
file=open(file_name,'w+')
|
||||
|
||||
# class_name
|
||||
world=table.split('_')
|
||||
worlds=[]
|
||||
for i in world:
|
||||
worlds.append(i.capitalize())
|
||||
|
||||
class_name='_'.join(worlds)
|
||||
class_name=class_name+"_sql"
|
||||
|
||||
file.write(class_name+"\n")
|
||||
file.write(schema+"."+table+"\n")
|
||||
for l in record:
|
||||
col_name,col_type,col_default=l
|
||||
file.write ("%s\t|%s\t|%s\n"%(col_name,col_type,col_default))
|
||||
|
||||
file.close()
|
||||
print "file %s has been created "%(file_name)
|
||||
print "check that the first column is the primary key"
|
||||
|
|
@ -77,7 +77,7 @@ class @class_name@ @mother_class@
|
|||
|
||||
if ( $p_id == -1 ) {
|
||||
/* Initialize an empty object */
|
||||
foreach ($this->variable as $key=>$value) $this->$value='';
|
||||
foreach ($this->variable as $key=>$value) $this->$value='DEFAULT';
|
||||
$this->@id@=$p_id;
|
||||
} else {
|
||||
/* load it */
|
||||
|
|
@ -474,13 +474,14 @@ class @class_name@
|
|||
mother_name=''
|
||||
mother_class=''
|
||||
table=line[1].strip()
|
||||
(id,type_id)=line[2].strip().split('|')
|
||||
(id,type_id,default)=line[2].strip().split('|')
|
||||
id=id.strip()
|
||||
column_noid=''
|
||||
column_this=''
|
||||
column_select=''
|
||||
column_insert=''
|
||||
fileoutput=open("class_"+class_name.lower()+".php",'w+')
|
||||
print "Create the file %s "+fileoutput.name
|
||||
|
||||
sep=''
|
||||
i=1
|
||||
|
|
@ -539,7 +540,7 @@ class @class_name@
|
|||
if e.find('|') < 0 :
|
||||
continue
|
||||
|
||||
(col_id,col_type)=e.split('|')
|
||||
(col_id,col_type,default)=e.split('|')
|
||||
col_id=col_id.strip()
|
||||
col_type=col_type.strip()
|
||||
if col_type in ('float','integer','numeric','bigint') :
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue