SQL Server SqlPackage variables: are quotes needed around string variable? - sql-server

When running sqlpackage.exe for deployments, do string variables require quotes around the word? It seems to be running successfully both ways. What is the correct syntax?
Two options shown here:
/v:CompanyName=ABCD
/v:CompanyName="ABCD"
Resource: https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage?view=sql-server-ver15

#Jeroen Mostert is right. It's more related to the command line not only the SqlPackage.
If the string variable contains spaces equality signs, slashes, or anything else that would interfere with option syntax, the value must be surrounded in "quotes".
Here is the example blog: https://www.addictivetips.com/windows-tips/enter-file-or-folder-paths-with-spaces-in-command-prompt-on-windows-10/
If all of the following conditions are met, then quote characters on the command line are preserved:
No /S switch (Strip quotes)
Exactly two quote characters
No special characters between the two quote characters, where special is one of: & < >( ) # ^ |
There are one or more whitespace characters between the the two quote characters
The string between the two quote characters is the name of an executable file.
Ref: https://ss64.com/nt/syntax-cmd.html
HTH.

Related

Regex inside split() method unintended side-effect [duplicate]

$.validator.addMethod('AZ09_', function (value) {
return /^[a-zA-Z0-9.-_]+$/.test(value);
}, 'Only letters, numbers, and _-. are allowed');
When I use somehting like test-123 it still triggers as if the hyphen is invalid. I tried \- and --
Escaping using \- should be fine, but you can also try putting it at the beginning or the end of the character class. This should work for you:
/^[a-zA-Z0-9._-]+$/
Escaping the hyphen using \- is the correct way.
I have verified that the expression /^[a-zA-Z0-9.\-_]+$/ does allow hyphens. You can also use the \w class to shorten it to /^[\w.\-]+$/.
(Putting the hyphen last in the expression actually causes it to not require escaping, as it then can't be part of a range, however you might still want to get into the habit of always escaping it.)
The \- maybe wasn't working because you passed the whole stuff from the server with a string. If that's the case, you should at first escape the \ so the server side program can handle it too.
In a server side string: \\-
On the client side: \-
In regex (covers): -
Or you can simply put at the and of the [] brackets.
Generally with hyphen (-) character in regex, its important to note the difference between escaping (\-) and not escaping (-) the hyphen because hyphen apart from being a character themselves are parsed to specify range in regex.
In the first case, with escaped hyphen (\-), regex will only match the hyphen as in example /^[+\-.]+$/
In the second case, not escaping for example /^[+-.]+$/ here since the hyphen is between plus and dot so it will match all characters with ASCII values between 43 (for plus) and 46 (for dot), so will include comma (ASCII value of 44) as a side-effect.
\- should work to escape the - in the character range. Can you quote what you tested when it didn't seem to? Because it seems to work: http://jsbin.com/odita3
A more generic way of matching hyphens is by using the character class for hyphens and dashes ("\p{Pd}" without quotes). If you are dealing with text from various cultures and sources, you might find that there are more types of hyphens out there, not just one character. You can add that inside the [] expression

JREPL.bat regex replacing inside quotes

Im using JREPL.BAT to find and replace specific instances and my regex I have works for find and replace in VSC code and also in the couple regex editors I've used.
CALL ./framework/config/JREPL.BAT "(Error)+\(([^()]*|\(([^()]*|\([^()]*\))*\))*\)" "Error(\"\")" /f ./dist/index.html /o
so what I'm expecting is it to find any case of
Error("")
or
Error( skjdksjdskd() + "" + )
etc
Find and replace works perfectly but jrepl takes
Error( skjdksjdskd() + "" + )
and changes it to
Error()( skjdksjdskd() + "" + )
does anyone know with more JREPL experience know why its ignoring the quotes and also not replacing the () area?
JREPL is hybrid JScript/batch that uses CSCRIPT - the Windows script host.
CSCRIPT has an inherent limitation that prevents double quote literals from being passed as parameters - there is no CSCRIPT escape sequence that includes a " literal.
To include a " literal in your query string, you can use \x22 instead. All of the standard JScript escape sequences can be used in the query string. By default, escape sequences are not recognized in the replace string.
But you want a quote literal in your replace string. This requires the /XSEQ option so you can use the JREPL extended escape sequence of \q. A significant advantage of this option is you can also use the extended escape sequences in the replace string. You could also use \x22 for both the search and replace strings if you prefer, but I find \q much easier to remember.
You have one other potential problem - the CALL command doubles all quoted carets, so [^()] (any character other than ( or )) becomes [^^()] (any character other than ^, ( or )). This is definitely not what you want. That is the reason I added the \c = ^ extended escape sequence.
So I believe the following will give your expected result:
CALL .\framework\config\JREPL.BAT "(Error)+\(([\c()]*|\(([\c()]*|\([\c()]*\))*\))*\)" "Error(\q\q)" /xseq /f .\dist\index.html /o -
FYI - The effect of the ^ beginning of string anchor is not harmed by caret doubling - you don't need the \c escape sequence for the beginning of string anchor because "^MatchStringBeginning" and "^^MatchStringBeginning" yield identical regex results.
You can get more information about the extended escape sequences by issuing jrepl /?/xseq, or jrepl /??/xseq for paged help.
>jrepl /?/xseq
/XSEQ - Enables extended escape sequences for both Search strings and
Replacement strings, with support for the following sequences:
\\ - Backslash
\b - Backspace
\c - Caret (^)
\f - Formfeed
\n - Newline
\q - Quote (")
\r - Carriage Return
\t - Horizontal Tab
\v - Vertical Tab
\xnn - Extended ASCII byte code expressed as 2 hex digits nn.
The code is mapped to the correct Unicode code point,
depending on the chosen character set. If used within
a Find string, then the input character set is used. If
within a Replacement string, then the output character
set is used. If the selected character set is invalid or
not a single byte character set, then \xnn is treated as
a Unicode code point. Note that extended ASCII character
class ranges like [\xnn-\xnn] should not be used because
the intended range likely does not map to a contiguous
set of Unicode code points - use [\x{nn-mm}] instead.
\x{nn-mm} - A range of extended ASCII byte codes for use within
a regular expression character class expression. The
The min value nn and max value mm are expressed as hex
digits. The range is automatically expanded into the
full set of mapped Unicode code points. The character
set mapping rules are the same as for \xnn.
\x{nn,CharSet} - Same as \xnn, except explicitly uses CharSet
character set mapping.
\x{nn-mm,CharSet} - Same as \x{nn-mm}, except explicitly uses
CharSet character set mapping.
\unnnn - Unicode code point expressed as 4 hex digits nnnn.
\u{N} - Any Unicode code point where N is 1 to 6 hex digits
JREPL automatically creates an XBYTES.DAT file containing all 256
possible byte codes. The XBYTES.DAT file is preferentially created
in "%ALLUSERSPROFILE%\JREPL\" if at all possible. Otherwise the
file is created in "%TEMP%\JREPL\" instead. JREPL uses the file
to establish the correct \xnn byte code mapping for each character
set. Once created, successive runs reuse the same XBYTES.DAT file.
If the file gets corrupted, then use the /XBYTES option to force
creation of a new XBYTES.DAT file. If JREPL cannot create the file
for any reason, then JREPL silently defaults to using pre v7.4
behavior where /XSEQ \xnn is interpreted as Windows-1252. Creation
of XBYTES.DAT requires either CERTUTIL.EXE or ADO. It is possible
that both may be missing from an XP machine.
Without the /XSEQ option, only standard JSCRIPT escape sequences
\\, \b, \f, \n, \r, \t, \v, \xnn, \unnnn are available for the
search strings. And the \xnn sequence represents a unicode
code point, not extended ASCII.
Extended escape sequences are supported even when the /L option
is used. Both Search and Replace support all of the extended
escape sequences if both the /XSEQ and /L options are combined.
Extended escape sequences are not applied to JScript code when
using any of the /Jxxx options. Use the decode() function if
extended escape sequences are needed within the code.
Final Answer for this is to escape the quotes and backslashes as \" AND \\ when using CALL in Webpack-shell-plugin.
'call "./framework/config/JREPL.BAT" \"(Error)\\(([\\c()]*|\\(([\\c()]*|\\([\\c()]*\\))*\\))*\\)\" \"Error(\\q\\q)\" /xseq /f ./dist/index.html /o ./dist/indexFinal.html'

Single Quotes or No quotes in file paths in Unix shells

I am new to Unix systems and trying to learn some thing with help of terminal. I have following question in my mind. If we can write filepath without single quotes in terminal (for ex : mv path1 path2) then why we sometime use single quotes to specify paths. What is the difference between these two?
This is not a question of the operating system, but of the shell you use. You can actually chose what shell you want to use on a unixoid system if multiple are installed (which usually is the case).
In general the shell has to interpret the input you make. It has to decide how to handle the tokens of the input. What to consider as the "command" you want to execute, what as arguments. For the arguments it has to decide if the string is meant as a single argument or multiple arguments.
Without quotes (single or double quotes), whitespace characters are considered separators between words, words are typically considered separate arguments. So you can specify multiple arguments for a single command. If that is not desired then you can use quote characters to group multiple words separated by whitespace characters into a single argument, for example a folder name containing a space character. This works because now the shell knows that you want everything following the quote character to be considered as a single argument up to the next matching quote character (actually except escaped ones...).
It's used to escape spaces in file names, otherwise, a backslash is needed. For instance:
$ rm spaces\ in\ file\ name
$ rm 'spaces in file name'
If your file path does not have spaces, it's probably safe to omit the quotes.

Unable to create directory in oracle 12c

I am using Oracle 12.2 .I wish to import data pump files. To do that, I wish to create a directory, containing the files and then import. I use the following command to create directory
CREATE DIRECTORY dpump_dir1 AS ‘D:\dumpdir’;
I am getting the error as
SQL Error: ORA-00911: invalid character
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
Could anybody tell me what is going wrong?
The quotes being used in the code you provided are not simple straight single quotes; it's slightly easier to see when formatted as code:
CREATE DIRECTORY dpump_dir1 AS ‘D:\dumpdir’;
You can also use your text editor or dump the string to see which chraacters it contains:
select dump(q'[CREATE DIRECTORY dpump_dir1 AS ‘D:\dumpdir’;]', 1016) from dual;
DUMP(Q'[CREATEDIRECTORYDPUMP_DIR1AS‘D:\DUMPDIR’;]',1016)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Typ=96 Len=49 CharacterSet=AL32UTF8: 43,52,45,41,54,45,20,44,49,52,45,43,54,4f,52,59,20,64,70,75,6d,70,5f,64,69,72,31,20,41,53,20,20,e2,80,98,44,3a,5c,64,75,6d,70,64,69,72,e2,80,99,3b
You can see that it's reported at 49 bytes despite being 45 characters long, indicating you have multibyte characters. Before the final semicolon, which is shown as 3b, you have the sequence e2,80,99 which represents the ’ right single quotation mark, and a bit earlier you have the sequence e2,80,98 which represents the ‘ left single quotation mark.
If you use plain quotes it should work:
CREATE DIRECTORY dpump_dir1 AS 'D:\dumpdir';
Presumably you copied and pasted the text from an editor which helpfully substituted curly quotes.

string literals/escapes

I am wondering if there is some sort of string prefix so that the cstring is taken as is without the need of my escaping all the characters. I am not 100% sure. I remember something about prefixing the string with the # symbol ( char str[] = #"some\text\here"; ) and you would not need to escape any of your characters such as \, \n,.etc. im working with curl and urls and it is a pain to have to escape every single backslash.
can anyone spread some light on this or am i stuck escaping every character prefixed with a backslash?
No. In C there are only two types of "string", the string literal surrounded by double quotes and the char literal surrounded by single quotes.
In both cases you must backslash escape characters that have special meaning.
This feature is not available in C. It seems you read about verbatim string literals of C#
and if you have to escape - escape characters in C you need to escape that using backslash ( \ )
In C, there is no such thing. You are stuck escaping everything, or perhaps you could put your URLs in a file and read them in.

Resources