Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ADO COM - Database Query


  • Please log in to reply
8 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
It queries the database through ADO.

NEED: COM Standard Library.

; Adjust sSource and sConnect appropriately
sSource  := "SELECT * FROM " . "atlas" ; . " WHERE country LIKE 'A%'"
sConnect := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . "C:\Database\atlas.mdb"

COM_Init()
prs :=	COM_CreateObject("ADODB.Recordset")
COM_Invoke(prs, "Open", sSource, sConnect)
Loop
{
	If	COM_Invoke(prs, "EOF")
		Break
	pFields	:= COM_Invoke(prs, "Fields")
	Loop, %	COM_Invoke(pFields, "Count")
		pField:= COM_Invoke(pFields, "Item", A_Index-1)
	,	sData .= COM_Invoke(pField, "Name") . ": " . COM_Invoke(pField, "Value") . "`r`n"
	,	COM_Release(pField)
	COM_Release(pFields)
	COM_Invoke(prs, "MoveNext")
}
COM_Invoke(prs, "Close")
COM_Release(prs)
COM_Term()
MsgBox, % sData


PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Beside the base functionality (which is useful), it seems you offer a good range of helper functions for Com support.
I guess it needs the latest version of AutoHotkey (v.1.0.46.08 at least), you should have mentioned it to avoid messages like "It doesn't work"...
Do you know a good online tutorial for Com? I always wanted to learn it, but never went very far, this could be a good new opportunity.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Beside the base functionality (which is useful), it seems you offer a good range of helper functions for Com support.

Thanks. As a matter of fact, I originally planned to upload it as CoHelper.ahk. But, I was not sure if it had to be. BTW, I removed a few APIs to reduce the size of the script.

I guess it needs the latest version of AutoHotkey (v.1.0.46.08 at least), you should have mentioned it to avoid messages like "It doesn't work"...

I was aware of it, but forgot to do it. Thanks for mentioning it.

Do you know a good online tutorial for Com? I always wanted to learn it, but never went very far, this could be a good new opportunity.

Probably the most frequently opened file lately in my system has been Platform SDK Documentation. If I didn't get enough information from it, then I went to MSDN or googled it.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Yesterday, 07:41 AM
  • Joined: 24 May 2006
I know superb COM tutorial. I have read 4,5 of them already using different languages, but this one makes it crystal clear. It describes COM architecture in detail rather then explaining how to use it. It does so by creating simple COM object starting from blank C struct that at the end becomes valid COM class.

There are 6 articles (some form of mini book). Its made by the man who created cwebpage.dll. My recomendation is to go to tutorial 6 (last one) and download the source code for it. In that archive, the author made html with all 6 articles, and all 6 source archives in the form of book with the TOC.

This is the link to the first article:
<!-- m -->http://www.codeproje...m/com_in_c1.asp<!-- m -->

This is the link to the package containing all 6:
<!-- m -->http://www.codeproje... ... c6_src.zip<!-- m -->

Its really extraoridnary set of articles. Don't miss it. Read every one of them as they are connected. Then you will see COM in its real lite.

I was learning this to understand Seans code better and to see what should I do to create COM interface in AHK. This article showed me that it is possible to create such thing in AHK to behave the very same as for instance in VBScript. TypeLibraries that are needed to decifer COMs data structures and interfaces are available as COM objects too, and those can be quieried in AHK to create VTable that can be used to invoke COM object inteface methods from the ahk script.

2 Sean
If you want to create COM interface in AHK for AHK then I suggest you to create new topic on AHK Wiki so all interested can colaborate. I have pretty good understanding about the topic now, seems that PhilHo and foom are willing to help too... This is good oportunity for all of us to learn more about COM and do something useful for the community along the way.
Posted Image

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

2 Sean
If you want to create COM interface in AHK for AHK then I suggest you to create new topic on AHK Wiki so all interested can colaborate. I have pretty good understanding about the topic now, seems that PhilHo and foom are willing to help too... This is good oportunity for all of us to learn more about COM and do something useful for the community along the way.

I wish I could. Unfortunately, however, I can't as I'm not a programmer, have no programming experience at all.

Anyway, looks like you're now better prepared than me for this job, even if I have a programming skill. I stopped reading the fabulous articles you mentioned around article 3 or 4.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

Probably the most frequently opened file lately in my system has been Platform SDK Documentation. If I didn't get enough information from it, then I went to MSDN or googled it.

That might be a good reference, but hardly a good tutorial! ;-) Or I might have missed something.

I know superb COM tutorial.

Many thanks, I will look into it.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Yesterday, 07:41 AM
  • Joined: 24 May 2006

I wish I could. Unfortunately, however, I can't as I'm not a programmer, have no programming experience at all.

ha ha... you are strange guy Sean. Why the hell did you read COM articles if you are not a programmer ? I mean, its hard core programming topic....

Anyway, looks like you're now better prepared than me for this job, even if I have a programming skill. I stopped reading the fabulous articles you mentioned around article 3 or 4.

I wish I have all the time to spend on this. However life in Serbia is not so relaxed. Our parlament just brought the new law witch basicly states that none in government institutions will have salary rise in next 6 years ! :lol: I will probably have to change my job soon and switch to private sector, witch will leave even less time for this. I will try to do something, nevertheless. I am at article 4 now :) and cumulating information from previous 3 wasn't easy. I still have to sort things in my head about COM and why are some things done that way, and not some other...
Posted Image

washboard
  • Guests
  • Last active:
  • Joined: --
Can you please give an example of the instruction to read an Excel sheet, please ? Would it be possible to implement the reading of float values ?
Thanks for your answer.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Can you please give an example of the instruction to read an Excel sheet, please ? Would it be possible to implement the reading of float values ?

Unfortunately I can't as MS Office is not installed on my system. I hope other users help.