query:
call myProc();
How to get column names from result?
There are dynamically generated column names inside this proc, so I cannot just query db to return me column names.
const q = sql"select * from mytable"
var c: DbColumns
for row in db.instantRows(q, c):
echo row[0]
echo c
got this
641014
@[]
641015
@[]
how is it possible?
If you know the table name being used in the stored procedure, then you can query the information_schema to get column names.
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'foo' AND TABLE_NAME ='bar';
as I said, I cannot use query like this, because it is not table, it's dynamically generated pivot table, to column names are generated dynamically, like this
Your question was unclear.
I would take a look at the code for instantRows iterator and do something similar with the addition of calling fetch_fields to get field information from the result set and returning a data structure that includes field names and row results.
There is an overload to instantRows which takes a var seq[DbColumn] as in
iterator instantRows*(db: DbConn; columns: var DbColumns; query: SqlQuery;
args: varargs[string, `$`]): InstantRow =
So you should be able to do something like:
var cols : DbColumns = @[]
for x in db.instantRows(cols, query):
for idx, col in cols:
echo col.name