resourceless database connection metadata

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

resourceless database connection metadata

#1

Postby Segi » Fri Mar 24, 2017 5:34 pm

How do I get the metadata from a resourceless database connection.

I need to be able to access the column names that are returned by a query pragmatically since my application lets you view a DB table's schema and I won't know the column names until the user chooses a table to see the schema for. So I need to be able to access the column names through code.

With the old way I do

Code: Select all

stmt = con.prepareStatement(fields.SQLCMD.value);
rs = stmt.executeQuery();
     
rsm=new java.sql.ResultSetMetaData(rs.getMetaData());
With the new way you do

Code: Select all

function (columnData) {
// get column names here
});
How do I get the column names pragmatically
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Fri Mar 24, 2017 6:10 pm

columnData is a JS object that contains a value for each NON-NULL column, so you can get the column names with:

Code: Select all

for (var colName in columnData)
{
 ..
}
But this is a bit flaky: firstly the number of columns returned might vary with each row returned, secondly columns with null values aren't returned (I think), thirdly the query might return no rows so the callback function is never executed.

Unfortunately there is no way to access ResultSetMetaData using the services.database.xx methods.

For info, an alternative to ResultSetMetaData is to use DatabaseMetaData to find all the columns in any given table. This is the best option for looking at single tables - but no use if you have joins. But to use any of these metadata objects you need to code it the old way - with JDBC statements.
0 x


Who is online

Users browsing this forum: No registered users and 128 guests