FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

i fail to get the column name by using odbc

 
Post new topic   Reply to topic     Forum Index -> DDBI
View previous topic :: View next topic  
Author Message
davidl



Joined: 17 Aug 2006
Posts: 27

PostPosted: Tue Oct 31, 2006 9:54 pm    Post subject: i fail to get the column name by using odbc Reply with quote

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
View user's profile Send private message
davidl



Joined: 17 Aug 2006
Posts: 27

PostPosted: Tue Oct 31, 2006 11:10 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
jpelcis



Joined: 09 Mar 2006
Posts: 40

PostPosted: Wed Nov 01, 2006 5:43 pm    Post subject: Reply with quote

Thanks again. This is fixed, too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DDBI All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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