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 

Need help in SQLCMD Automation

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



Joined: 08 Jan 2009
Posts: 2

PostPosted: Tue Mar 24, 2009 3:10 pm    Post subject: Need help in SQLCMD Automation Reply with quote

Hi Guys !
im trying to create a script / procedure which will do as followed

Get 22 Tokens sepereted by "," and will do an insert command using sqlcmd

i.e -

call SQLCMD.EXE with the following arguments
-s HostName -d Somthing -u Somthing -p Somthing -Q "exec EventInfoIns @StatusCd='Token1' , @UserName='Token2' ...etc.. (till token 22)

So the script will be ran as followed
SQL Token1,Token2,Token3,Token4 and etc...

thanks!
Back to top
View user's profile Send private message
ProsperousOne



Joined: 19 Sep 2005
Posts: 115

PostPosted: Tue Mar 24, 2009 7:19 pm    Post subject: Reply with quote

Don't know if this will help, but I just completed a beta script to query a PostgreSQL database.

Hope this helps. (Script not tested).

Code:
; Thanks to _dave_ on 2p2 forums
#SingleInstance Force
#Persistent
#NoEnv

SQLsince := "00:00:00 01/01/09"
ScreenName := "Bob"

;modify below for sql query statement
sql := "select count(playerhandscashkeycolumns_hero.netamountwon)
, sum(playerhandscashkeycolumns_hero.netamountwon) from players
, playerhandscashkeycolumns_hero where (players.playername = '" . ScreenName . "')
and  (playerhandscashkeycolumns_hero.handtimestamp  > '" . SQLsince . "');"

HandData := psql(sql)

msgbox, %HandData%

Return

#Esc::
ExitApp

psql(sql="", database="", debug=0, host="", username="")
{
  ; set default values below if you want to use different all the time

  if (database = "")
  {
    database := "postgres"
  }

  if (host = "")
  {
    host := "localhost"
  }

  if (username = "")
  {
    username := "postgres"
  }

  ; END default value section

  ; Delete previous files from previous execution if it still exists
  FileDelete, SQLinputFile.txt
  FileDelete, SQLoutputFile.txt
  FileDelete, SQLerrorFile.txt

  ; Create psql query statement file
  FileAppend,  \f '\t'`n, SQLinputFile.txt ; changes field separator to tab character ('\t')
  FileAppend, %sql%`n, SQLinputFile.txt    ; add sql query statement
  FileAppend,  \q`n, SQLinputFile.txt      ; quit psql

  ; Create psql input parameter string
  ; -A :unalign (uncenter) output columns
  ; -t : remove headers & footers
  ; -d : specify which postgreSQL database (Holdem Manager Database) to use
  ; -f : name of file contaning psql commands to process
  ; -0 : nmae of psql output file
  ; -2>: direct any errors to this file
  command := "psql.exe -A -t -d " . database . " -f SQLinputFile.txt -o SQLoutputFile.txt  2> SQLerrorFile.txt"

  RunWait, %comspec% /c %command% , , Hide

  FileGetSize, errorsize, SQLerrorFile.txt

  If (errorsize > 0)
  {
    FileRead, errortext, SQLerrorFile.txt

    FileDelete, SQLinputFile
    FileDelete, SQLoutputFile
    FileDelete, SQLerrorFile

    if (debug)
    {
      Msgbox, %errorcause%`n`n`n%errortext%
      ExitApp
    }
    else
    {
      FileAppend, %A_Now% - An Error Occured:`n`nInput:`n%errorcause%`n`nOutput:`n%errortext%`n`n`n`n, %A_Scriptname%_Error_Log.txt
    }
  }

  FileRead, sqlout, SQLoutputFile.txt  ; load output into sqlout variable
  ; delete files
  FileDelete, SQLinputFile.txt
  FileDelete, SQLoutputFile.txt
  FileDelete, SQLerrorFile.txt

  StringTrimRight, sqlout, sqlout, 2 ; remove line feed from output

  return %sqlout%   ; return data
Back to top
View user's profile Send private message
m0tek



Joined: 08 Jan 2009
Posts: 2

PostPosted: Thu Mar 26, 2009 9:15 am    Post subject: Reply with quote

mmm
naw , i only need somthing to automate SQLCMD ;(
Back to top
View user's profile Send private message
Display posts from previous:   
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