Get table name from column name

Is there a function in Servoy to get the table name from a column name? Trying to use new createDataSource and we are tired of hand coding all the column types. We can get the column names from a dataset but we can’t find a way to get the column types of those columns. It sure would be great to have getColumnType function that worked on a dataset. We do have one for a table, but not for a dataset which might contain columns from multiple tables. dataset.getColumnType(MyColumnName) is what I’m looking for. Then I can loop through all the columns in a dataset and return a list of column types to pass to createDataSource.

var uri = dataset.createDataSource(‘mydata2’, [DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT]);

If we didn’t have to hand code all the DM_COLUMTYPE.TEXT entries we can write a ‘universal’ function to handle all the different dataset we need to build, instead of each one being hand coded.

Gary

Hi Gary,

I can’t think of a direct way.
If your columnnames are uniquely named (even crosstable) you could consider looping through all tables & all columns to find a matching name…
If you need this often create an object on startup, so you can call this quickly and get your tablename returned easily.

Good luck!

By default a dataset doesnt know the column types.
Because you can create a dataset from anything, by just specifying the column names

But i guess we can enhance this by also be able to specify types and if you query from the database it is auto filled in for you

please make a feature request for this

In release 4.2 the types argument to createDataSource will be optional.
When the data set is created from a query the types return from the query can be used.

Rob

Thanks Rob!

That is a huge time saving for us and I’m sure will be appreciated by many developers.

Gary