question

Hao Zhou avatar image
0 Likes"
Hao Zhou asked Hao Zhou commented

Questions about database connector

Hi,

I have a few questions about database connector:

1. Is there a way of setting cursor to the front of result set? For example, in MySQL C++ connector, they have function like

  1. resultSet->beforeFirst(); // Put cursor to the beginning

2. Is there a way of getting metadata from result set? For example, in MySQL C++ connector, if we want to print all the column name from result set, we can

  1. sql::ResultSetMetaData *metaData = resultSet->getMetaData();
  2. int nrCols = metaData->getColumnCount();
  3. for (int i = 1; i <= nrCols; i++)
  4. {
  5. pt(metaData->getColumnName(i));
  6. pt(", ");
  7. }

3. How do I know the value returned from result set is an int or double? The value we get from resultSet[i] is a Variant. We are able to know if the value is a number or not. But we do not know if the number is a int or double.

Thanks,

Hao

FlexSim 18.1.1
database connector
· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered Phil BoBo edited

It seems that the Database.ResultSet class does not support random access, just forward iteration, and getting metadata like column names or data types is not possible. As an answer to your first two questions then, it is probably best if you just dump the result set to a table using the cloneTo method, and then use the Table interface to get the information you want.

This would be a useful addition, so I would support your request for this, though I am not sure how hard it is to implement. FlexSim uses a C++ library that is able to connect to various databases so presumably they can only add this functionality if that library supports it. In your post you compare to the C++ MySQL-specific interface, but in general it is difficult to make things work consistently across all the database flavors out there.

As for the third question, that would be solved by allowing you to request the data type of a column in the result set; but for now you could do it the "old-fashioned" way - like you do it with any Variant variable, e.g. any of

  1. Variant val = 42;
  2. isInt = Math.frac(val) == 0;
  3. isInt = val == Math.floor(val);
  4. isInt = val - Math.trunc(val) == 0;
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.