Jump to content

Problem with IniRead


Ptica
 Share

Recommended Posts

Hello,

I need help with reading ini file.

I have the following:

ini file:

[settings]

query= Select * from " & $servername & " where date=curdate()"

Script:

tried both:

$queryLogger='"' & IniRead(@ScriptDir & "\" & $optionsFile, "settings", "query_logger", "")&'"'

and

$queryLogger=IniRead(@ScriptDir & "\" & $optionsFile, "settings", "query_logger", "")

As a result I get : "SELECT * FROM " & $servername & " where date = curdate()"

$servername is not resolved.

If I write $queryLogger="SELECT * FROM " & $servername & " where date = curdate()", then I get the following string:

SELECT * FROM MyServerName where date = curdate().

Could somebody explain what I'm doing wrong?

I could not find the answer in the forum.

Thanks in advance

Link to comment
Share on other sites

IniRead() returns a string, nothing more. It sounds to me like you need Execute(), try this:

$servername = "iamonkey"
$sTest = '"Select * from " & $servername & " where date=curdate()"'

MsgBox(0, "", $sTest)
MsgBox(0, "", Execute($sTest))
Link to comment
Share on other sites

Ptica,

#cs
[settings]
; Notice the additional $ after the variable name, this is because of the Opt("ExpandVarStrings",1) line.
query= Select * from $servername$ where date= $Curdate$
[]
#ce
Opt("ExpandVarStrings",1)
$Servername = "AnyOldName"
$CurDate = @MDAY &'/'& @MON &'/'& @YEAR
$IniData = IniRead(@SCRIPTFULLPATH,"settings","query","fubar!")
ConsoleWrite($IniData & @LF)

*Shakes fist* beaten by the Admiral. :mellow:

Edited by Mobius

wtfpl-badge-1.png

Link to comment
Share on other sites

Ptica,

#cs
[settings]
; Notice the additional $ after the variable name, this is because of the Opt("ExpandVarStrings",1) line.
query= Select * from $servername$ where date= $Curdate$
[]
#ce
Opt("ExpandVarStrings",1)
$Servername = "AnyOldName"
$CurDate = @MDAY &'/'& @MON &'/'& @YEAR
$IniData = IniRead(@SCRIPTFULLPATH,"settings","query","fubar!")
ConsoleWrite($IniData & @LF)

*Shakes fist* beaten by the Admiral. :mellow:

Great! Thanks a lot, it worked!

I had no chance to find this without your help.

Cheers!

Link to comment
Share on other sites

IniRead() returns a string, nothing more. It sounds to me like you need Execute(), try this:

$servername = "iamonkey"
$sTest = '"Select * from " & $servername & " where date=curdate()"'

MsgBox(0, "", $sTest)
MsgBox(0, "", Execute($sTest))

Wow, it works too.

So many options to solve it and I could not find any.

Thanks a lot for your help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...