How to iterate over database tables?

I am trying to iterate over database tables using the following code that got an error java.lang.UnsupportedOperationException. I even tried with cfloop query and other attributesgetting errors a complex value cannot convert to a simple value. can someone tell me how i have to iterate over this query? Thank.

<cfquery name="q" datasource="datasource">
    SHOW TABLES FROM datasource
</cfquery>
<cfloop collection ="#q#" item="i">
   #q[i]#
</cfloop> 
+3
source share
3 answers

You get this error because cfloop collectionexpects a structure, not a request object. Therefore, the error is "UnsupportedOperation ...".

Instead, you should use a query loop. The generated column name is dynamic, based on your database name. You can either hardcode it or access it dynamically:

   <cfset colNames = listToArray(q.columnList)>
   <cfoutput query="q">
      <cfloop array="#colName#" index="col">
            #q[col][currentRow]#
      </cfloop>
      <br>
   </cfoutput>

, INFORMATION_SCHEMA. , . , .

    <cfquery name="yourQueryName" ...>
       SELECT  TABLE_NAME
       FROM    INFORMATION_SCHEMA.TABLES
       WHERE   TABLE_SCHEMA = 'YourDatabaseName'
    </cfquery>

    <cfoutput query="yourQueryName">
         #TABLE_NAME# <br>
    </cfoutput>
+5

CFDBINFO? "tabes" , .

+1

What about

<cfoutput query="q">
#tables#
<cfoutput>
0
source

All Articles