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

ODBC Interface (Windows)

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



Joined: 18 Jul 2005
Posts: 8

PostPosted: Sat Jan 28, 2006 4:06 pm    Post subject: ODBC Interface (Windows) Reply with quote

Well, after more headaches than I would have liked or care to admit, I am now happily using DDBI to connect to various databases with reckless abandon! There is now an odbc directory in the SVN. While there is some of room for improvement in how DDBI looks and feels, I find it very soothing to hide all of the nasty ODBC calls behind the relative simplicity of DDBI. Just like you'd think, you go like this:

Code:

import dbi.odbc.odbcDatabase;

int main() {

  odbcDatabase db = new odbcDatabase();       

  db.connect("Demo");      
  db.close();   


  return 0;
}



Or if you prefer, connect DSN-lessly:

Code:

  db.connect(r"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\dmd\Demo.mdb");



The catch is that you will need to have 5 extra files in std/c/windows. You can download "ODBC Headers for D" here: http://spottedtiger.tripod.com/D_Language/D_Support_Projects_XP.html. Obviously, I am not the author of these files, and none of this would have been possible without "David L.", the author. I felt that it made a lot more sense to use this pre-existing work, and make DDBI require these files, than to rewrite these files in a DDBI way. I also didn't think that these files properly belonged in DDBI. I'd like to hear everyone's thoughts on this, and I don't want to cause any trouble.

This will only work in Windows, because the headers are Windows (odbc32.dll). I am unsure of the demand for Linux ODBC support, and I doubt that I could put it together. I've included a Makefile.win in Subversion. Hopefully I'll hear reports that someone else has gotten this to work. =) Just reply to this thread. DDBI is important to me and I hope that this will be seen as a practical and useful addition!

About the code itself, I doubt it's especially fast or efficient. I'm sure that I've left plenty of room for optimization, and it is ODBC after all. Shocked I'll probably be touching the code up a bit in the next few days, but honestly right now I'm just pretty happy that it seems to work for me, and will be a pretty helpful tool for a lot of the projects that I'm working on.

I worked really hard on this so I don't want to hear any comments about how there is no such thing as an "ODBC Database" Twisted Evil I'm just following convention that doesn't quite fit in this case. I'm sure we'll all manage. Cool

Enjoy! And let me know what you think!
_________________
Mark Delano
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sun Jan 29, 2006 11:25 pm    Post subject: Reply with quote

This is very good news. Very Happy With access to ODBC (especially DSN-less ODBC) comes access to many different kind of databases. Exclamation

Since it's always better to make things easier to use, I wonder if SpottedTiger would allow you to copy his files and slightly modify them (e.g. move them to dbi/odbc) so that they could be redistributed as part of the DDBI package. What you've proposed (installing the ODBC into dmd\src\phobos) would work, but it could lead to more trouble with remembering that needs to be there when setting up D on another computer and things like that. Maybe I just worry too much. Of course, if we could get Walter to include these headers with the DMD package, that'd be terrific. But it's like pulling teeth to get him to add stuff to Phobos, so that's a lost cause. Sad
Back to top
View user's profile Send private message AIM Address
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