View previous topic :: View next topic |
Author |
Message |
davidl
Joined: 17 Aug 2006 Posts: 27
|
Posted: Tue Oct 31, 2006 9:54 pm Post subject: i fail to get the column name by using odbc |
|
|
import dbi.Row;
import dbi.odbc.OdbcDatabase;
import std.stdio;
pragma(lib,"odbc32.lib"); //this still doesn't work . i need to build it with odbc32.lib in command line. NOTE: i have odbc32.lib in my dmd\lib path
void main() {
OdbcDatabase db = new OdbcDatabase();
writefln("hello");
db.connect("DRIVER={SQL Server};PWD=userpass;UID=user;SERVER=mydatabase-server;database=mydatabase");
writefln("connect");
Row[] rows = db.queryFetchAll("SELECT field1,field2 FROM temp ");
int i=0;
foreach (Row row; rows)
{ i++;
writefln(row[""]); //this would show the field1, but i can't get field2 anymore , and this behaves abnormally IMHO
}
writefln("after for each");
scope (exit)
{
db.close(); //this always tells me unable to close odbc environment
}
} |
|
Back to top |
|
|
davidl
Joined: 17 Aug 2006 Posts: 27
|
Posted: Tue Oct 31, 2006 11:10 pm Post subject: |
|
|
due to the document in :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/
htm/odbcsqlcolattribute.asp
i find odbcresult.d line 119 should be :
if (!SQL_SUCCEEDED(SQLColAttribute(stmt, i, SQL_DESC_NAME, columnName, columnName.length, &columnNameLength, null))) {
throw new DBIException("Unable to get the SQL column names. ODBC returned " ~ getLastErrorMessage, getLastErrorCode);
}
SQL_DESC_NAME is going to tell the api to get the column alias, if not , we would possibly get only an empty string |
|
Back to top |
|
|
jpelcis
Joined: 09 Mar 2006 Posts: 40
|
Posted: Wed Nov 01, 2006 5:43 pm Post subject: |
|
|
Thanks again. This is fixed, too. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|