AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL Query/Extraction Using ADO help needed

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
silveredge78



Joined: 25 Jul 2006
Posts: 387
Location: Midwest, USA

PostPosted: Fri May 23, 2008 10:27 pm    Post subject: SQL Query/Extraction Using ADO help needed Reply with quote

I am trying to use the code found here by tfcahm. I have gotten it to work in terms of extracting files from SQL. However, I was wondering how I could use it to pull out actual exported records like I would using isqlw or t4esql. If I can get that, then I can process through that list and know what files to pull down.

Here is my code so far:

Code:
 Author:   tfcahm
; Found at: http://www.autohotkey.com/forum/viewtopic.php?p=137323#137323

#SingleInstance Force
#Persistent
#NoEnv
SetBatchLines, -1
SendMode, Input

#Include CoHelper.ahk
CoInitialize()

sFileOut = %A_Desktop%\test_out.doc   ;output file, will be overwritten if exists
 
;Some useful constants
Jet3x:=4, Jet4x:=5
adOpenKeyset:=1, adLockOptimistic:=3, adTypeBinary:=1
adSaveCreateOverWrite:=2, adInteger:=3, adKeyPrimary:=1
VT_I4:=0x3, VT_BSTR:=0x8, VT_DISPATCH:=0x9, VT_UI1:=0x11, VT_ARRAY:=0x2000

;::::::::::::::::::::::::::::::::::::::::::::::::::
;  Write binary data from the database into a file
;::::::::::::::::::::::::::::::::::::::::::::::::::

;Define the connection string
sConn := "Driver={SQL Server};Server=SqlServerName;Database=SQLDatabaseName;Uid=SQLUsername;Pwd=SQLPassword;"
 
;Create and open a connection
pcn := ActiveXObject("ADODB.CONNECTION")
Invoke(pcn, "Open", sConn)

;Create and open the recordset with a query
prs := ActiveXObject("ADODB.RECORDSET")
Invoke_(prs, "Open", VT_BSTR,"Select * From TP_Document Where PD_OwnerKey = '24195' And PD_Key = '127142';"
                   , VT_DISPATCH,pcn
                   , VT_I4,adOpenKeyset
                   , VT_I4,adLockOptimistic)

;Create and open a binary stream
pmstream := ActiveXObject("ADODB.STREAM")
Invoke(pmstream, "Type=", adTypeBinary)
Invoke(pmstream, "Open")

;Write the value of the target field to the stream object and then save it to a file with overwrite
pFields := Invoke(prs, "Fields")
pField := Invoke(pFields, "Item", "PD_Object")
pSafearray:=Invoke(pField, "Value")
Invoke_(pmstream, "Write", VT_ARRAY|VT_UI1,pSafearray)
Invoke(pmstream, "SavetoFile", sFileOut, adSaveCreateOverWrite)

;Cleanup, conservative - release every IDispatch
DllCall("oleaut32\SafeArrayDestroy", "Uint", pSafeArray)
Release(pField)
Release(pFields)
Invoke(pcn, "Close")
Invoke(prs, "Close")
Release(pmstream)
Release(prs)
Release(pcn)

CoUninitialize()
Msgbox, Done!
ExitApp

I know the SQL query I want to pull the list of accounts, and how to pull the list of documents based off that list. But only using isqlw. I'd like to do it all in AHK. Also, I'd like to do it without crazy nested loops.

Any help would be greatly appreciated.
_________________
SilverEdge78
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1397

PostPosted: Sat May 24, 2008 2:50 am    Post subject: Reply with quote

I'm not entirely sure of what you'd like to do, but have you seen the post by tfcahm again a few pages before the page you linked?
http://www.autohotkey.com/forum/topic16565.html
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group