我在许多PS脚本中都使用了这种类型的编码:
/*
* If it might be a number, try converting it. If a number cannot be
* produced, then the value will just be a string.
*/
char initial = string.charAt(0);
if ((initial >= '0' && initial <= '9') || initial == '-') {
try {
// if we want full Big Number support this block can be replaced with:
// return stringToNumber(string);
if (isDecimalNotation(string)) {
Double d = Double.valueOf(string);
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
} else {
Long myLong = Long.valueOf(string);
if (string.equals(myLong.toString())) {
if (myLong.longValue() == myLong.intValue()) {
return Integer.valueOf(myLong.intValue());
}
return myLong;
}
}
} catch (Exception ignore) {
}
}
它工作良好,直到其中一个变量的值包含冒号(例如$SQlScriptParameters = (
"FtpServer='$FtpServer'",
"RotkatalogFörFTP='$RootFolderOnFtpServer'",
"HostUrlForWebAuthorization='$HostUrlForWebAuthorization'",
"UrlForSsekListener='$UrlForSsekListener'",
"RotkatalogFörAvstämningar='$RootFolderForReconciliations'",
"UrlFörWebbtjänsten='$UrlForWebSite'"
)
$result = Invoke-Sqlcmd -ServerInstance '(local)' -Database "$DatabaseName" -InputFile "$SqlAdaptSystemParameters" -QueryTimeout $maxQueryTime -AbortOnError -Variable $SQlScriptParameters
)为止。现在,我收到以下解析错误:
$HostUrlForWebAuthorization
在Windows PowerShell ISE调试器中显示时,Invoke-Sqlcmd :
At line:1 char:1
+ Invoke-Sqlcmd -ServerInstance '(local)' -Database "$DatabaseName" -In ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
字符串数组中的字符串值如下:
$SQlScriptParameters
这是SQL输入文件中的样子
HostUrlForWebAuthorization='http://ensymappacc1.cypointmo.local:80/'
如何设置SET NOCOUNT ON
DECLARE @FtpServer nvarchar(500)
DECLARE @RotkatalogFörFTP nvarchar(500)
DECLARE @HostUrlForWebAuthorization nvarchar(500)
DECLARE @UrlFörSsekLyssnaren nvarchar(500)
DECLARE @RotkatalogFörAvstämningar nvarchar(500)
DECLARE @UrlFörWebbtjänsten nvarchar(500)
-- Format: uname:pwd@hostname:port
SET @FtpServer = $(FtpServer)
SET @RotkatalogFörFTP = $(RootFolderForFTP)
-- Format: http://hostname:port/
SET @HostUrlForWebAuthorization = $(HostUrlForWebAuthorization)
SET @UrlFörSsekLyssnaren = $(UrlFörSsekLyssnaren)
SET @RotkatalogFörAvstämningar = $(RotkatalogFörAvstämningar)
-- Format: https://hostname:port/
SET @UrlFörWebbtjänsten = $(UrlFörWebbtjänsten)
,这样就不会在冒号上出现解析错误?