diff --git a/dev/manage-code/create-file/create_config.py b/dev/manage-code/create-file/create_config.py new file mode 100755 index 000000000..38831becc --- /dev/null +++ b/dev/manage-code/create-file/create_config.py @@ -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" diff --git a/dev/manage-code/create-file/create_phpclass.py b/dev/manage-code/create-file/create_phpclass.py index 38a07c138..0c6c60aa2 100755 --- a/dev/manage-code/create-file/create_phpclass.py +++ b/dev/manage-code/create-file/create_phpclass.py @@ -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') :