AutoHotkey Community

It is currently May 26th, 2012, 4:27 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: March 24th, 2009, 4:10 pm 
Offline

Joined: January 8th, 2009, 10:24 pm
Posts: 2
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2009, 8:19 pm 
Offline

Joined: September 19th, 2005, 1:31 am
Posts: 115
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2009, 10:15 am 
Offline

Joined: January 8th, 2009, 10:24 pm
Posts: 2
mmm
naw , i only need somthing to automate SQLCMD ;(


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, SKAN, tterB and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group