coldfusion - Code guidance required for creating mysql table from what is returned by the CFDBINFO Tag -
working following code..
i had tried till create mysql table cfdbinfo, missing few things things here like:
- unique key
- index key
here following try me, please provide enhancements
<cffunction access="public" name="advancedbackup" returntype="any"> <cfargument name="structform" default="" required="no" type="struct"> <cfset var mystruct = ""> <cfset getinfo = getbackupdatabasetables('szone')> <cfset gettableengines = valuelist(getinfo.name)> <cfdbinfo datasource="supportzone" name="getcolumns" type="columns" table="#listlast(arguments.structform.id,'~')#" /> <cfsavecontent variable="tablename"> create table `<cfoutput>#listlast(arguments.structform.id,'~')#</cfoutput>`( </cfsavecontent> <cfsavecontent variable="tablecontents"> <cfloop query="getcolumns"> <cfoutput> `#column_name#` <cfif column_size gt 255 , type_name neq 'varchar'> text <cfelseif type_name 'datetime'> datetime <cfelseif type_name 'timestamp'> timestamp <cfelse> #type_name#(#column_size#) </cfif> <cfif is_primarykey 'yes'> auto_increment </cfif> , <cfif is_primarykey 'no'> default <cfif column_default_value ''> null, <cfelse> '#column_default_value#' <cfif is_nullable 'no'> not null, <cfelse> null, </cfif> </cfif> </cfif> </cfoutput> </cfloop> <cfoutput> primary key (` <cfif getcolumns.is_primarykey 'yes'> #getcolumns.column_name# </cfif> `) ) engine = <cfif listfindnocase(gettableengines,listlast(arguments.structform.id,'~'),',') neq 0> #getinfo.engine# auto_increment=#getinfo.auto_increment# </cfif> ; </cfoutput> </cfsavecontent> <cfset ftable = tablename & tablecontents> <cfdump var="#ftable#" abort>
so basically, getbackupdatabasetables getting following query
show table status szone
it looks trying copy structure of existing table new table. create template table in db, backup_tbl_tmp. can have keys , indexes need. create new table (in mysql i'm assuming using...) do:
create table new_table_name backup_tbl_tmp;
for mssql use:
select * new_table_name backup_tbl 0=1;
note in mssql indexes not copied. if want copy data new table drop clause.
Comments
Post a Comment