<cfquery name="getData" datasource="#session.newdsn#">
SELECT * FROM #url.tableName#
</cfquery>
<cfset columsList = getData.columnList>
<table align="center" width="100%">
<tr align="left">
<cfloop list="#columsList#" index="i">
<cfoutput>
<th class="bgcolor">#i#</th>
</cfoutput>
</cfloop>
</tr>
<cfoutput>
<cfloop from="1" to="#getData.recordCount#" index="a">
<tr>
<cfloop from="1" to="#ListLen(columsList)#" index="i">
<cfset col=ListGetAt(getData.columnList,i)>
<td><input type="text" name="#i#" value="#Evaluate("getData.#col#[#a#]")#" /></td>
</cfloop>
</tr>
</cfloop>
</cfoutput>
</table>
On This Line
<td><input type="text" name="#i#" value="#Evaluate("getData.#col#[#a#]")#" /></td>
I have to put the name of Column [name="#i#"], but if i use the same as value it gets the rows name and if i use #i#, i get the values as numeric.
Now i have confusion how i put the column Name in place of {Name="#i#"} and how i do multiple update
Regards
<cfparam name="FORM.startrow" default="1">
<cfset FORM.maxrows = 50>
<cfquery name="getData" datasource="#session.newdsn#">
SELECT * FROM #url.tableName#
</cfquery>
<cfparam name="FORM.columsList" default="#getData.columnList#">
<cfparam name="FORM.PKcolumn" default="">
<cfif FORM.PKcolumn is "">
<cfif listcontains(FORM.columnlist, "#url.tableName#_ID")>
<cfset FORM.PKcolumn = url.tableName & "_ID">
<cfelse>
<cfset FORM.PKcolumn = url.tableName>
</cfif>
</cfif>
<form ...>
<cfoutput>
<input type="hidden" name="columnList" value="#FORM.columnList#" />
<input type="hidden" name="PKcolumn" value="#FORM.PKcolumn#" />
<input type="hidden" name="startrow" value="#FORM.startrow#" />
<input type="hidden" name="maxrows" value="#FORM.maxrows#" />
</cfoutput>
<table align="center" width="100%">
<tr align="left">
<cfloop list="#FORM.columsList#" index="col">
<cfoutput><th class="bgcolor">#col#</th></cfoutput>
</cfloop>
</tr>
<cfoutput query="getData">
<tr>
<cfloop list="#FORM.columnList#" index="col">
<td>
<input type="text" name="#col#_#getData[PKcolumn][currentrow]" value="#getData[col][currentrow]#" <cfif col eq FORM.PKcolumn>disabled="disabled"</cfif> />
</td>
</cfloop>
</tr>
</cfoutput>
...
</form>
<cfparam name="FORM.startrow" default="1">
<cfset FORM.maxrows = 50>
<!---<cfif isdefined('form.updaterows')>
<cfdump var="#form#"><cfabort>
<cfquery name="updateData" datasource="#session.newdsn#">
<!--- do whatever your update is --->
</cfquery>
</cfif>--->
<cfif isdefined('url.mode')>
<cfif url.mode eq 'rows'>
<cfquery name="getData" datasource="#session.newdsn#">
SELECT * FROM #url.tableName#
</cfquery>
<cfparam name="FORM.columnlist" default="#getData.columnList#">
<cfparam name="FORM.PKcolumn" default="">
<cfif FORM.PKcolumn is "">
<cfif listcontains(FORM.columnlist, "#url.tableName#_ID")>
<cfset FORM.PKcolumn = url.tableName & "_ID">
<cfelse>
<cfset FORM.PKcolumn = url.tableName>
</cfif>
</cfif>
<cfform method="post" action="#CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#">
<table align="center" width="100%">
<tr align="left">
<cfoutput>
<input type="hidden" name="columnList" value="#FORM.columnList#" />
<input type="hidden" name="PKcolumn" value="#FORM.PKcolumn#" />
<input type="hidden" name="startrow" value="#FORM.startrow#" />
<input type="hidden" name="maxrows" value="#FORM.maxrows#" />
</cfoutput>
<table align="center" width="100%">
<tr align="left">
<cfloop list="#FORM.columnlist#" index="col">
<cfoutput><th class="bgcolor">#col#</th></cfoutput>
</cfloop>
</tr>
<cfoutput query="getData">
<tr>
<cfloop list="#FORM.columnList#" index="col">
<td>
<input type="text" name="#col#_#getData[PKcolumn][currentrow]#" value="#getData[col][currentrow]#" <cfif col eq FORM.PKcolumn>disabled="disabled"</cfif>>
</td>
</cfloop>
</tr>
</cfoutput>
<tr>
<td align="center"><cfoutput><input type="hidden" name="tableName" value="#url.tablename#" /></cfoutput><input type="submit" name="updaterows" value="Update" /></td>
</tr>
</table>
</cfform>
</cfif>
</cfif>
Here is the Source Code what is it:
<form name="CFForm_1" id="CFForm_1" action="rows.cfm?mode=rows&tableName=grcountry" method="post" onsubmit="return _CF_checkCFForm_1(this)">
<table align="center" width="100%">
<tr align="left">
<th class="bgcolor">COUNTRY</th>
<th class="bgcolor">COUNTRY_NAME</th>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="1" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Afghanistan" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="2" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Albania" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="3" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Algeria" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="4" /></td>
<td><input type="text" name="COUNTRY_NAME" value="American Samoa" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="5" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Andorra" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="6" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Angola" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="7" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Anguilla" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="8" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Antarctica" /></td>
</tr>
<tr>
<td><input type="text" name="COUNTRY" value="9" /></td>
<td><input type="text" name="COUNTRY_NAME" value="Antigua and Barbuda" /></td>
</tr>
</cfform>
<cfparam name="url.maxrows" default="50">
<cfparam name="url.startrow" default="1">
<cfparam name="FORM.startrow" default="#url.startrow#">
<!--- process form data if form has been submitted --->
<cfif isDefined("form.saveData")>
<!--- you might want to put the update query below in a cftry/cfcatch block to trap any errors and output them nicely formatted instead of as default cf error message--->
<cfloop index="recNum" from="1" to="#FORM.recordCount#">
<cfquery name="updateTable" datasource="#application.dsn#">
UPDATE #FORM.tableName#
SET
<cfloop list="#FORM.dataColumns#" index="col">
<cfset theValue = form[col & '_' & recNum]>
#col# = <cfif len(trim(theValue)) eq 0>NULL
<cfelseif isNumeric(theValue)>#theValue#
<cfelseif isValid('date', theValue) OR (listLen(theValue,"/") gt 2 AND isDate(theValue))>#createODBCDateTime(theValue)#
<cfelse>'#theValue#'
</cfif>
<cfif col neq listlast(FORM.dataColumns)>,</cfif>
</cfloop>
WHERE #FORM.PKcolumn# = <cfif isNumeric(form[FORM.PKcolumn & '_' & recNum])><cfqueryparam cfsqltype="cf_sql_numeric" value="#form[FORM.PKcolumn & '_' & recNum]#"><cfelse><cfqueryparam cfsqltype="cf_sql_varchar" value="#form[FORM.PKcolumn & '_' & recNum]#"></cfif>
</cfquery>
</cfloop>
<!--- increment FORM.startrow var to show next block of 50 rows --->
<cfset FORM.startrow = FORM.startrow + url.maxrows>
<cfelse>
<!---
set required FORM variables if this is the first call to this page [form has never been submitted yet].
(only need to set these once on first call to this page - after this all these vars are available in the FORM scope
since they are set as hidden form fields in the form.)
--->
<!--- set and check FORM.mode var--->
<cfparam name="url.mode" default="">
<cfparam name="form.mode" default="#trim(url.mode)#">
<cfif form.mode is not "Rows">
<h1>Mode is not set to rows</h1>
<cfabort>
</cfif>
<!--- set and check FORM.tableName var--->
<cfparam name="url.tableName" default="">
<cfparam name="FORM.tableName" default="#trim(url.tableName)#">
<cfif len(trim(FORM.tableName)) is 0>
<h1>No table selected</h1>
<cfabort>
</cfif>
<!--- get db table metadata to extract PK column name --->
<cfdbinfo name="getDataInfo" datasource="#application.dsn#" table="#FORM.tableName#" type="columns">
<!--- extract PK column name from table metadata and set form variable --->
<cfparam name="FORM.PKcolumn" default="">
<cfloop query="getDataInfo">
<cfif getDataInfo.IS_PRIMARYKEY>
<cfset FORM.PKcolumn = getDataInfo.COLUMN_NAME>
<cfbreak>
</cfif>
</cfloop>
<cfif len(trim(FORM.PKcolumn)) is 0>
<h1>No Primary Key defined in table</h1>
<cfabort>
</cfif>
</cfif>
<!--- get table data --->
<cfquery name="getData" datasource="#application.dsn#">
SELECT * FROM #FORM.tableName#
</cfquery>
<cfif NOT structkeyexists(FORM, "dataColumns")>
<!--- set FORM.dataColumn to list of table columns without PK column --->
<!--- only executes if FORM.dataColumns is not defined yet (i.e. on first call to this page) --->
<cfset PKColPosition = listFindNoCase(getData.columnList, FORM.PKcolumn)>
<cfset FORM.dataColumns = listDeleteAt(getData.columnList, PKColPosition)>
</cfif>
<!---
show table edit form.
only output form if not all table rows have been processed/updated yet
--->
<cfif FORM.startrow lte getData.recordcount>
<cfform name="form1" action="#getfilefrompath(cgi.script_name)#" method="post">
<cfinput type="hidden" name="mode" value="#FORM.mode#" />
<cfinput type="hidden" name="tableName" value="#FORM.tableName#" />
<cfinput type="hidden" name="PKcolumn" value="#FORM.PKcolumn#" />
<cfinput type="hidden" name="dataColumns" value="#FORM.dataColumns#" />
<cfinput type="hidden" name="startrow" value="#FORM.startrow#" />
<table align="center" width="100%" border="1" cellpadding="3">
<tr>
<th class="bgcolor"><cfoutput>#ucase(FORM.PKcolumn)#</cfoutput></th>
<cfloop list="#FORM.dataColumns#" index="col">
<th class="bgcolor"><cfoutput>#col#</cfoutput></th>
</cfloop>
</tr>
<cfoutput query="getData" startrow="#FORM.startrow#" maxrows="#url.maxrows#">
<cfset curRow = getData.currentrow>
<tr>
<td><input type="text" name="#FORM.PKcolumn & '_' & curRow#" value="#getData[FORM.PKcolumn][curRow]#" readonly="readonly" style="background-color:##e9e9e9;" size="6" /></td>
<cfloop list="#FORM.dataColumns#" index="col">
<td><input type="text" name="#col & '_' & curRow#" value="#getData[col][curRow]#" /></td>
</cfloop>
</tr>
</cfoutput>
</table>
<cfinput type="hidden" name="recordcount" value="#curRow#" />
<p style="text-align:center;"><input type="submit" name="saveData" value="Update" /></p>
</cfform>
<cfelse>
<!---
all rows in the table have been updated already (FORM.startrow > getData.recordcount)
do want you need to do, i.e. cflocate to a page listing all tables
--->
<h3>Good job! You have edited all rows in [<cfoutput>#FORM.tableName#</cfoutput>] table!</h3>
</cfif>
<cfparam name="FORM.startrow" default="1">
<cfset FORM.maxrows = 50>
<cfparam name="url.mode" default="">
<cfif url.mode is not "Rows">
<h1>Mode is not set to rows</h1>
<cfexit>
</cfif>
<cfparam name="url.tableName" default="">
<cfset theTable = url.tableName>
<cfif len(theTable) eq 0>
<h1>Table name is required on URL</h1>
<cfexit>
</cfif>
<cfquery name="getData" datasource="#request.datasource#"> <!--- #session.newdsn# ---->
SELECT * FROM #theTable#
</cfquery>
<cfset dataColumns = getData.columnList> <!--- a list of all data columns ---->
<!--- find the primary key column automatically ----->
<cfdbinfo name="getInfo" datasource="#request.datasource#" table="#theTable#" type="columns">
<cfquery name="getKey" dbtype="query">
select * from getInfo where IS_PRIMARYKEY = 'YES'
</cfquery>
<cfset primaryKey = getKey.COLUMN_NAME>
<!---- remove the primary key from the list of columns, so we don't update it ---->
<cfset pos = listFindNoCase(dataColumns,primaryKey)>
<cfif pos eq 0>
<cfoutput>
<h1>Warning Primary Key [#primaryKey#] is not in the table [#theTable#]</h1>
<p>IF the primary key is not called [#primaryKey#] then enter it in the structure
called variables.primaryKeys so we know the name of the key for this table</p>
</cfoutput>
<cfexit>
<cfelse>
<cfset dataColumns = listDeleteAt(dataColumns,pos)>
</cfif>
<cfif isDefined("form.saveData")>
<cfloop index="recNum" from="1" to="#form.recordCount#">
<cfset theFirst = true> <!--- flag to track the first record, for comma placement ---->
<cfquery name="updateTable" datasource="#request.datasource#">
update #theTable#
set
<cfloop list="#dataColumns#" index="col">
<cfif NOT theFirst>,<cfelse><cfset theFirst=false></cfif>
<cfset theValue = form[col & '_' & recNum]>
#col# = <cfif len(trim(theValue)) eq 0>NULL
<cfelseif listLen(theValue,"/") gt 2 and isDate(theValue)>#createODBCdate(theValue)#
<cfelseif isNumeric(theValue)>#theValue#
<cfelse>'#theValue#'
</cfif>
</cfloop>
where #primaryKey# = #form[primaryKey & '_' & recNum]#
</cfquery>
</cfloop>
</cfif>
<cfset numCols = listLen(dataColumns)>
<cfform>
<table align="center" width="100%" border="1" cellpadding="3">
<tr align="left">
<tr align="left">
<th><cfoutput>#primaryKey#</cfoutput></th>
<cfloop list="#dataColumns#" index="col">
<cfoutput><th class="bgcolor">#col#</th></cfoutput>
</cfloop>
</tr>
<cfoutput query="getData">
<tr>
<td><input type="text" name="#primaryKey#_#getData.currentrow#" value="#getData[primaryKey][getData.currentrow]#" readonly="readonly" style="background-color:##e9e9e9;"></td>
<cfloop list="#dataColumns#" index="col">
<td>
<input type="text" name="#col#_#getData.currentrow#" value="#getData[col][getData.currentrow]#">
</td>
</cfloop>
</tr>
</cfoutput> <!--- loop each record ---->
<tr>
<cfoutput>
<td align="left" colspan="#numCols+1#">
<input type="hidden" name="recordCount" value="#getData.recordCount#">
</cfoutput>
<input type="submit" name="saveData" value="Update" />
</td>
</tr>
</table>
</cfform>
<!--- get db table metadata to extract PK column name --->
<cfparam name="FORM.PKcolumn" default="">
<cftry>
<cfdbinfo name="getDataInfo" datasource="#application.dsn#" table="#FORM.tableName#" type="columns">
<!--- extract PK column name from table metadata and set form variable --->
<cfloop query="getDataInfo">
<cfif getDataInfo.IS_PRIMARYKEY>
<cfset FORM.PKcolumn = getDataInfo.COLUMN_NAME>
<cfbreak>
</cfif>
</cfloop>
<cfcatch>
<cfloop array="#getmetadata(getData)#" index="colStruct">
<cfif colStruct['TypeName'] is 'COUNTER'>
<cfset FORM.PKcolumn = colStruct['Name']>
<cfbreak>
</cfif>
</cfloop>
</cfcatch>
</cftry>
<cfif len(trim(FORM.PKcolumn)) is 0>
<h1>No Primary Key defined in table</h1>
<cfabort>
</cfif>
<cfcomponent>
<cffunction name="init" returntype="AccessDBUtil" access="public" >
<cfargument name="jdbcDatasourceName" type="string" required="true" />
<cfset setDatasourceName(arguments.jdbcDatasourceName) />
<cfreturn this />
</cffunction>
<cffunction name="setDatasourceName" returntype="void" access="private" >
<cfargument name="jdbcDatasourceName" type="string" required="true" />
<cfset variables.instance.datasource = arguments.jdbcDatasourceName />
</cffunction>
<cffunction name="getDatasourceName" returntype="string" access="public" >
<cfreturn variables.instance.datasource />
</cffunction>
<cffunction name="getCatologs" returntype="query" access="public" >
<cfset var Local = structNew() />
<cfset Local.connection = getConnection() />
<cfset Local.resultset = Local.connection.getMetaData().getCatalogs() />
<cfset Local.query = resultsetToQuery( resultset = Local.resultset ) />
<cfset Local.resultset.close() />
<cfset Local.connection.close() />
<cfreturn Local.query />
</cffunction>
<cffunction name="getSchemas" returntype="query" access="public" output="true" >
<cfset var Local = structNew() />
<cfset Local.connection = getConnection() />
<cfset Local.resultset = Local.connection.getMetaData().getSchemas() />
<cfset Local.query = resultsetToQuery( resultset = Local.resultset ) />
<cfset Local.resultset.close() />
<cfset Local.connection.close() />
<cfreturn Local.query />
</cffunction>
<cffunction name="getTableTypes" returntype="query" access="public" >
<cfset var Local = structNew() />
<cfset Local.connection = getConnection() />
<cfset Local.resultset = Local.connection.getMetaData().getTableTypes() />
<cfset Local.query = resultsetToQuery( resultset = Local.resultset ) />
<cfset Local.resultset.close() />
<cfset Local.connection.close() />
<cfreturn Local.query />
</cffunction>
<cffunction name="getProcedures" returntype="query" access="public" output="false" >
<cfargument name="catalogName" type="string" required="false" hint="The name of a catolog in the database. An empty string means retrieve objects without a catalog. If not specified, the catolog is not used to narrow the search" />
<cfargument name="schemaPattern" type="string" required="false" default="%" hint="The name of a schema in the database. An empty string means retrieve objects without a schema. " />
<cfargument name="procedurePattern" type="string" required="false" default="%" />
<cfset var Local = structNew() />
<cfscript>
Local.isCatalogNonNull = structKeyExists(arguments, "catalogName");
Local.isSchemaNonNull = structKeyExists(arguments, "schemaPattern");
Local.connection = getConnection();
//TODO: check if there is a way to pass java NULL's conditionally
if ( Local.isCatalogNonNull AND Local.isSchemaNonNull ) {
Local.resultset = Local.connection.getMetaData().getProcedures( arguments.catalogName,
arguments.schemaPattern,
arguments.procedurePattern );
}
else if ( Local.isCatalogNonNull ) {
Local.resultset = Local.connection.getMetaData().getProcedures( arguments.catalogName,
javacast("null", ""),
arguments.procedurePattern );
}
else if ( Local.isSchemaNonNull ) {
Local.resultset = Local.connection.getMetaData().getProcedures( javacast("null", ""),
arguments.schemaPattern,
arguments.procedurePattern );
}
else {
Local.resultset = Local.connection.getMetaData().getProcedures( javacast("null", ""),
javacast("null", ""),
arguments.procedurePattern );
}
Local.query = resultsetToQuery( resultset = Local.resultset );
Local.resultset.close();
Local.connection.close();
</cfscript>
<cfreturn Local.query />
</cffunction>
<cffunction name="getTables" returntype="query" access="public" output="false" >
<cfargument name="catalogName" type="string" required="false" hint="The name of a catolog in the database. An empty string means retrieve objects without a catalog. If not specified, the catolog is not used to narrow the search" />
<cfargument name="schemaPattern" type="string" required="false" default="%" hint="The name of a schema in the database. An empty string means retrieve objects without a schema. " />
<cfargument name="tablePattern" type="string" required="false" default="%" />
<cfargument name="typeList" type="string" required="false" default="" hint="Comma delimited list of table types to include. An empty string means retrieve all types" />
<cfset var Local = structNew() />
<cfscript>
Local.isCatalogNonNull = structKeyExists(arguments, "catalogName");
Local.isTypeNonNull = len(trim(arguments.typeList));
Local.typeArray = listToArray(arguments.typeList);
Local.connection = getConnection();
//TODO: check if there is a way to pass java NULL's conditionally
if ( Local.isCatalogNonNull AND Local.isTypeNonNull ) {
Local.resultset = Local.connection.getMetaData().getTables( arguments.catalogName,
arguments.schemaPattern,
arguments.tablePattern,
Local.typeArray);
}
else if ( Local.isCatalogNonNull ) {
Local.resultset = Local.connection.getMetaData().getTables( arguments.catalogName,
arguments.schemaPattern,
arguments.tablePattern,
javacast("null", ""));
}
else if ( Local.isTypeNonNull ) {
Local.resultset = Local.connection.getMetaData().getTables( javacast("null", ""),
arguments.schemaPattern,
arguments.tablePattern,
Local.typeArray);
}
else {
Local.resultset = Local.connection.getMetaData().getTables( javacast("null", ""),
arguments.schemaPattern,
arguments.tablePattern,
javacast("null", ""));
}
Local.query = resultsetToQuery( resultset = Local.resultset );
Local.resultset.close();
Local.connection.close();
</cfscript>
<cfreturn Local.query />
</cffunction>
<cffunction name="getColumns" returntype="query" access="public" output="false" >
<cfargument name="catalogName" type="string" required="false" hint="The name of a catolog in the database. An empty string means retrieve objects without a catalog. If not specified, the catolog is not used to narrow the search" />
<cfargument name="schemaPattern" type="string" required="false" hint="The name of a schema in the database. An empty string means retrieve objects without a schema. If not specified, the schema is not used to narrow the search" />
<cfargument name="tablePattern" type="string" required="false" default="%" hint="Table name to find. Wildcards are NOT supported by com.inzoom.jdbcado driver" />
<cfargument name="columnPattern" type="string" required="false" default="%" hint="Column name to find. Wildcards are NOT supported by com.inzoom.jdbcado driver" />
<cfset var Local = structNew() />
<cfscript>
Local.isCatalogNonNull = structKeyExists(arguments, "catalogName");
Local.isSchemaNonNull = structKeyExists(arguments, "schemaPattern");
Local.connection = getConnection();
//TODO: check if there is a way to pass NULL's conditionally
if ( Local.isCatalogNonNull AND Local.isSchemaNonNull ) {
Local.resultset = Local.connection.getMetaData().getColumns( arguments.catalogName,
arguments.schemaPattern,
arguments.tablePattern,
arguments.columnPattern);
}
else if ( Local.isCatalogNonNull ) {
Local.resultset = Local.connection.getMetaData().getColumns( arguments.catalogName,
javacast("null", ""),
arguments.tablePattern,
arguments.columnPattern);
}
else if ( Local.isSchemaNonNull ) {
Local.resultset = Local.connection.getMetaData().getColumns( javacast("null", ""),
arguments.schemaPattern,
arguments.tablePattern,
arguments.columnPattern);
}
else {
Local.resultset = Local.connection.getMetaData().getColumns( javacast("null", ""),
javacast("null", ""),
arguments.tablePattern,
arguments.columnPattern);
}
Local.query = resultsetToQuery( resultset = Local.resultset );
//Local.query2 = createObject("java", "coldfusion.sql.QueryTable").init(Local.resultset);
Local.resultset.close();
Local.connection.close();
</cfscript>
<cfreturn Local.query />
</cffunction>
<cffunction name="getVersionInfo" returntype="query" access="public" >
<cfset var Local = structNew() />
<cfscript>
Local.query = queryNew( "DATABASE_VERSION,DATABASE_PRODUCTNAME" &
",DATABASE_MAJOR_VERSION,DATABASE_MINOR_VERSION," &
", DRIVER_VERSION,DRIVER_NAME,JDBC_MAJOR_VERSION," &
"JDBC_MINOR_VERSION");
Local.connection = getConnection();
Local.meta = getConnection().getMetaData();
Local.row = queryAddRow( Local.query, 1);
Local.query["DATABASE_PRODUCTNAME"][Local.row] = Local.meta.getDatabaseProductName();
Local.query["DATABASE_VERSION"][Local.row] = Local.meta.getDatabaseProductVersion();
Local.query["DATABASE_MAJOR_VERSION"][Local.row] = Local.meta.getDatabaseMajorVersion();
Local.query["DATABASE_MINOR_VERSION"][Local.row] = Local.meta.getDatabaseMinorVersion();
Local.query["DRIVER_VERSION"][Local.row] = Local.meta.getDriverVersion();
Local.query["DRIVER_NAME"][Local.row] = Local.meta.getDriverName();
Local.query["JDBC_MAJOR_VERSION"][Local.row] = Local.meta.getDriverMajorVersion();
Local.query["JDBC_MINOR_VERSION"][Local.row] = Local.meta.getDriverMinorVersion();
Local.connection.close();
</cfscript>
<cfreturn Local.query />
</cffunction>
<cffunction name="getConnection" returntype="any" >
<cfset var dsService = createObject("java", "coldfusion.server.ServiceFactory").getDataSourceService() />
<cfset var connection = dsService.getDataSource(getDatasourceName()).getConnection() />
<cfreturn connection />
</cffunction>
<cffunction name="getResultSetColumnNames" returntype="array" access="private" hint="Returns an array of column names from the resultset metadata" >
<cfargument name="resultsetMetadata" type="any" required="true" />
<cfset var Local = structNew() />
<cfscript>
Local.columnArray = arrayNew(1);
//get number of columns in the resulset
Local.maxColumn = arguments.resultsetMetadata.getColumnCount();
//get the name of each column in the query and append it to the array
for (Local.index = 1; Local.index LTE Local.MaxColumn; Local.index = Local.index + 1) {
arrayAppend( Local.columnArray, arguments.resultsetMetadata.getColumnName( javacast("int", Local.index)) );
}
</cfscript>
<cfreturn Local.columnArray />
</cffunction>
<cffunction name="resultsetToQuery" returntype="query" access="private" hint="Converts a resulset to a query object" >
<cfargument name="resultset" type="any" required="true" />
<cfset var Local = structNew() />
<!--- could also use "coldfusion.sql.QueryTable" to create a resulset
<cfset Local.query = createObject("java", "coldfusion.sql.QueryTable").init(arguments.resultset) />
--->
<cfscript>
Local.columnNames = getResultSetColumnNames( arguments.resultset.getMetaData() );
Local.maxColumn = arrayLen( Local.columnNames );
Local.query = queryNew( arrayToList(Local.columnNames) );
while ( arguments.resultset.next() ) {
//add one row to the query for each row in the resultset
Local.rowIndex = queryAddRow(Local.query , 1);
for ( Local.colIndex = 1; Local.colIndex LTE Local.maxColumn; Local.colIndex = Local.colIndex + 1) {
Local.colName = Local.columnNames[Local.colIndex];
Local.value = arguments.resultset.getObject( Local.colName );
// if the returned value is not NULL
if ( structKeyExists(Local, "value") ) {
Local.query[Local.colName][Local.rowIndex] = Local.value;
}
}
}
</cfscript>
<cfreturn Local.query />
</cffunction>
</cfcomponent>
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver]Optional feature not implemented
The error occurred in C:\Inetpub\wwwroot\Classic\listrows.cfm: line 224
222 : </cfif>
223 : <!--- get db table metadata to extract PK column name --->
224 : <cfdbinfo name="getDataInfo" datasource="#session.newdsn#" table="#FORM.tableName#" type="columns">
225 : <!--- extract PK column name from table metadata and set form variable --->
226 : <cfparam name="FORM.PKcolumn" default="">
<cfparam name="url.maxrows" default="50">
<cfparam name="url.startrow" default="1">
<cfparam name="FORM.startrow" default="#url.startrow#">
<!--- process form data if form has been submitted --->
<cfif isDefined("form.saveData")>
<!--- you might want to put the update query below in a cftry/cfcatch block to trap any errors and output them nicely formatted instead of as default cf error message--->
<cfloop index="recNum" from="1" to="#FORM.recordCount#">
<cfquery name="updateTable" datasource="#application.dsn#">
UPDATE #FORM.tableName#
SET
<cfloop list="#FORM.dataColumns#" index="col">
<cfset theValue = form[col & '_' & recNum]>
#col# = <cfif len(trim(theValue)) eq 0>NULL
<cfelseif isNumeric(theValue)>#theValue#
<cfelseif isValid('date', theValue) OR (listLen(theValue,"/") gt 2 AND isDate(theValue))>#createODBCDateTime(theValue)#
<cfelse>'#theValue#'
</cfif>
<cfif col neq listlast(FORM.dataColumns)>,</cfif>
</cfloop>
WHERE #FORM.PKcolumn# = <cfif isNumeric(form[FORM.PKcolumn & '_' & recNum])><cfqueryparam cfsqltype="cf_sql_numeric" value="#form[FORM.PKcolumn & '_' & recNum]#"><cfelse><cfqueryparam cfsqltype="cf_sql_varchar" value="#form[FORM.PKcolumn & '_' & recNum]#"></cfif>
</cfquery>
</cfloop>
<!--- increment FORM.startrow var to show next block of 50 rows --->
<cfset FORM.startrow = FORM.startrow + url.maxrows>
<cfelse>
<!---
set required FORM variables if this is the first call to this page [form has never been submitted yet].
(only need to set these once on first call to this page - after this all these vars are available in the FORM scope
since they are set as hidden form fields in the form.)
--->
<!--- set and check FORM.mode var--->
<cfparam name="url.mode" default="">
<cfparam name="form.mode" default="#trim(url.mode)#">
<cfif form.mode is not "Rows">
<h1>Mode is not set to rows</h1>
<cfabort>
</cfif>
<!--- set and check FORM.tableName var--->
<cfparam name="url.tableName" default="">
<cfparam name="FORM.tableName" default="#trim(url.tableName)#">
<cfif len(trim(FORM.tableName)) is 0>
<h1>No table selected</h1>
<cfabort>
</cfif>
<!--- get db table metadata to extract PK column name --->
<cfparam name="FORM.PKcolumn" default="">
<cftry>
<cfdbinfo name="getDataInfo" datasource="#application.dsn#" table="#FORM.tableName#" type="columns">
<!--- extract PK column name from table metadata and set form variable --->
<cfloop query="getDataInfo">
<cfif getDataInfo.IS_PRIMARYKEY>
<cfset FORM.PKcolumn = getDataInfo.COLUMN_NAME>
<cfbreak>
</cfif>
</cfloop>
<cfcatch>
<cfloop array="#getmetadata(getData)#" index="colStruct">
<cfif colStruct['TypeName'] is 'COUNTER'>
<cfset FORM.PKcolumn = colStruct['Name']>
<cfbreak>
</cfif>
</cfloop>
</cfcatch>
</cftry>
<cfif len(trim(FORM.PKcolumn)) is 0>
<h1>No Primary Key defined in table</h1>
<cfabort>
</cfif>
</cfif>
<!--- get table data --->
<cfquery name="getData" datasource="#application.dsn#">
SELECT * FROM #FORM.tableName#
</cfquery>
<cfif NOT structkeyexists(FORM, "dataColumns")>
<!--- set FORM.dataColumn to list of table columns without PK column --->
<!--- only executes if FORM.dataColumns is not defined yet (i.e. on first call to this page) --->
<cfset PKColPosition = listFindNoCase(getData.columnList, FORM.PKcolumn)>
<cfset FORM.dataColumns = listDeleteAt(getData.columnList, PKColPosition)>
</cfif>
<!---
show table edit form.
only output form if not all table rows have been processed/updated yet
--->
<cfif FORM.startrow lte getData.recordcount>
<cfform name="form1" action="#getfilefrompath(cgi.script_name)#" method="post">
<cfinput type="hidden" name="mode" value="#FORM.mode#" />
<cfinput type="hidden" name="tableName" value="#FORM.tableName#" />
<cfinput type="hidden" name="PKcolumn" value="#FORM.PKcolumn#" />
<cfinput type="hidden" name="dataColumns" value="#FORM.dataColumns#" />
<cfinput type="hidden" name="startrow" value="#FORM.startrow#" />
<table align="center" width="100%" border="1" cellpadding="3">
<tr>
<th class="bgcolor"><cfoutput>#ucase(FORM.PKcolumn)#</cfoutput></th>
<cfloop list="#FORM.dataColumns#" index="col">
<th class="bgcolor"><cfoutput>#col#</cfoutput></th>
</cfloop>
</tr>
<cfoutput query="getData" startrow="#FORM.startrow#" maxrows="#url.maxrows#">
<cfset curRow = getData.currentrow>
<tr>
<td><input type="text" name="#FORM.PKcolumn & '_' & curRow#" value="#getData[FORM.PKcolumn][curRow]#" readonly="readonly" style="background-color:##e9e9e9;" size="6" /></td>
<cfloop list="#FORM.dataColumns#" index="col">
<td><input type="text" name="#col & '_' & curRow#" value="#getData[col][curRow]#" /></td>
</cfloop>
</tr>
</cfoutput>
</table>
<cfinput type="hidden" name="recordcount" value="#curRow#" />
<p style="text-align:center;"><input type="submit" name="saveData" value="Update" /></p>
</cfform>
<cfelse>
<!---
all rows in the table have been updated already (FORM.startrow > getData.recordcount)
do want you need to do, i.e. cflocate to a page listing all tables
--->
<h3>Good job! You have edited all rows in [<cfoutput>#FORM.tableName#</cfoutput>] table!</h3>
</cfif>
Element COUNTRY_NAME_1 is undefined in a Java object of type class coldfusion.filter.FormScope.
The error occurred in C:\Inetpub\wwwroot\Classic\listrows.cfm: line 301
299 : SET
300 : <cfloop list="#FORM.dataColumns#" index="col">
301 : <cfset theValue = form[col & '_' & recNum]>
302 : #col# = <cfif len(trim(theValue)) eq 0>NULL
303 : <cfelseif isNumeric(theValue)>#theValue#
<cfset application.dsn = "lao_ngo0">
<cfparam name="url.maxrows" default="50">
<cfparam name="url.startrow" default="1">
<cfparam name="FORM.startrow" default="#url.startrow#">
<!---
set required FORM variables if this is the first call to this page [form has never been submitted yet].
(only need to set these once on first call to this page - after this all these vars are available in the FORM scope
since they are set as hidden form fields in the form.)
--->
<!--- set and check FORM.mode var--->
<cfparam name="url.mode" default="">
<cfparam name="FORM.mode" default="#trim(url.mode)#">
<cfif FORM.mode is not "Rows">
<h1>Mode is not set to rows</h1>
<cfabort>
</cfif>
<!--- set and check FORM.tableName var--->
<cfparam name="url.tableName" default="">
<cfparam name="FORM.tableName" default="#trim(url.tableName)#">
<cfif len(trim(FORM.tableName)) is 0>
<h1>No table selected</h1>
<cfabort>
</cfif>
<!--- process form data if form has been submitted --->
<cfif structkeyexists(FORM, 'saveData')>
<!--- you might want to put the update query below in a cftry/cfcatch block to trap any errors and output them nicely formatted instead of as default cf error message--->
<cfloop index="recNum" from="#FORM.startrow#" to="#FORM.recordCount#">
<cfquery name="updateTable" datasource="#application.dsn#">
UPDATE #FORM.tableName#
SET
<cfloop list="#FORM.dataColumns#" index="col">
<cfset theValue = form[col & '_' & recNum]>
#col# = <cfif len(trim(theValue)) eq 0>NULL
<cfelseif isNumeric(theValue)>#theValue#
<cfelseif isValid('date', theValue) OR (listLen(theValue,"/") gt 2 AND isDate(theValue))>#createODBCDateTime(theValue)#
<cfelse>'#theValue#'
</cfif>
<cfif col neq listlast(FORM.dataColumns)>,</cfif>
</cfloop>
WHERE #FORM.PKcolumn# = <cfif isNumeric(form[FORM.PKcolumn & '_' & recNum])><cfqueryparam cfsqltype="cf_sql_numeric" value="#form[FORM.PKcolumn & '_' & recNum]#"><cfelse><cfqueryparam cfsqltype="cf_sql_varchar" value="#form[FORM.PKcolumn & '_' & recNum]#"></cfif>
</cfquery>
</cfloop>
<!--- increment FORM.startrow var to show next block of 50 rows --->
<cfset FORM.startrow = FORM.startrow + url.maxrows>
</cfif>
<!--- get table data --->
<cfquery name="getData" datasource="#application.dsn#" cachedwithin="#createtimespan(0,0,10,0)#">
SELECT * FROM #FORM.tableName#
</cfquery>
<cfif NOT structkeyexists(FORM, 'saveData')>
<!--- only executes if FORM.dataColumns is not defined yet (i.e. on first call to this page) --->
<!--- get db table metadata to extract PK column name --->
<cfparam name="FORM.PKcolumn" default="">
<cftry>
<cfdbinfo name="getDataInfo" datasource="#application.dsn#" table="#FORM.tableName#" type="columns">
<!--- extract PK column name from table metadata and set form variable --->
<cfloop query="getDataInfo">
<cfif getDataInfo.IS_PRIMARYKEY>
<cfset FORM.PKcolumn = getDataInfo.COLUMN_NAME>
<cfbreak>
</cfif>
</cfloop>
<cfcatch>
<cfloop array="#getmetadata(getData)#" index="colStruct">
<cfif colStruct['TypeName'] is 'COUNTER'>
<cfset FORM.PKcolumn = colStruct['Name']>
<cfbreak>
</cfif>
</cfloop>
</cfcatch>
</cftry>
<cfif len(trim(FORM.PKcolumn)) is 0>
<h1>No Primary Key defined in table</h1>
<cfabort>
</cfif>
<!--- set FORM.dataColumn to list of table columns without PK column --->
<cfset PKColPosition = listFindNoCase(getData.columnList, FORM.PKcolumn)>
<cfset FORM.dataColumns = listDeleteAt(getData.columnList, PKColPosition)>
</cfif>
<!---
show table edit form.
only output form if not all table rows have been processed/updated yet
--->
<cfif FORM.startrow lte getData.recordcount>
<cfform name="form1" action="#getfilefrompath(cgi.script_name)#" method="post">
<cfinput type="hidden" name="mode" value="#FORM.mode#" />
<cfinput type="hidden" name="tableName" value="#FORM.tableName#" />
<cfinput type="hidden" name="PKcolumn" value="#FORM.PKcolumn#" />
<cfinput type="hidden" name="dataColumns" value="#FORM.dataColumns#" />
<cfinput type="hidden" name="startrow" value="#FORM.startrow#" />
<table align="center" width="100%" border="1" cellpadding="3">
<tr>
<th class="bgcolor"><cfoutput>#ucase(FORM.PKcolumn)#</cfoutput></th>
<cfloop list="#FORM.dataColumns#" index="col">
<th class="bgcolor"><cfoutput>#col#</cfoutput></th>
</cfloop>
</tr>
<cfoutput query="getData" startrow="#FORM.startrow#" maxrows="#url.maxrows#">
<cfset curRow = getData.currentrow>
<tr>
<td><input type="text" name="#FORM.PKcolumn & '_' & curRow#" value="#getData[FORM.PKcolumn][curRow]#" readonly="readonly" style="background-color:##e9e9e9;" size="6" /></td>
<cfloop list="#FORM.dataColumns#" index="col">
<td><input type="text" name="#col & '_' & curRow#" value="#getData[col][curRow]#" /></td>
</cfloop>
</tr>
</cfoutput>
</table>
<cfinput type="hidden" name="recordcount" value="#curRow#" />
<p style="text-align:center;"><input type="submit" name="saveData" value="Update" /></p>
</cfform>
<cfelse>
<!---
all rows in the table have been updated already (FORM.startrow > getData.recordcount)
do want you need to do, i.e. cflocate to a page listing all tables
--->
<h3>Good job! You have edited all rows in [<cfoutput>#FORM.tableName#</cfoutput>] table!</h3>
</cfif>
Putting aside your question for a moment .. do you realize that code is dangerous? Even if you are using Access. Â It allows anyone to pass in whatever table name they want in the url. Then your code would not only give them access to the information, but allow them to modify it too. Â For example, someone could pass in the name of your "user" table and proceed to steal everyone's password.