column aliases not shown with columnames
Mostrar comentarios más antiguos
Is it possilbe to get the column alias names from a query using the Matlab Database toolbox?
I'm running Matlab R2011b and using the Database Toolbox to interface with a MySQL database. The connector I'm using is:
mysql-connector-java-5.1.20-bin.jar
Here's the database object I create:
>> dbh
dbh =
Instance: 'instance'
UserName: 'myname'
Driver: 'com.mysql.jdbc.Driver'
URL: 'jdbc:mysql://mysql1.m.r.edu/coolops'
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: []
Handle: [1x1 com.mysql.jdbc.JDBC4Connection]
TimeOut: 5
AutoCommit: 'on'
Type: 'Database Object'
When I execute a query that uses a column alias:
>> sth = exec(dbh, 'SELECT id AS did FROM missions')
and fetch the first result:
>> sth = fetch(sth,1)
sth =
Attributes: []
Data: {[2]}
DatabaseObject: [1x1 database]
RowLimit: 0
SQLQuery: 'SELECT id AS did FROM missions'
Message: []
Type: 'Database Cursor Object'
ResultSet: [1x1 com.mysql.jdbc.JDBC4ResultSet]
Cursor: [1x1 com.mathworks.toolbox.database.sqlExec]
Statement: [1x1 com.mysql.jdbc.StatementImpl]
Fetch: [1x1 com.mathworks.toolbox.database.fetchTheData]
Checking the column names:
>> columnnames(sth, true)
ans =
'id'
The column alias does not show up. Rather it's the actual column name from the table. This becomes a problem when trying to do a join on 2 tables that have the same column name since I don't have the column alias names from the query in the result.
How do you get column aliases from a result set?
Respuesta aceptada
Más respuestas (1)
Jordan
el 2 de Feb. de 2016
1 voto
It's years late, but I had the same problem and nobody online had solved it for me. Try the attached.
Categorías
Más información sobre MySQL Native Interface en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!