How to do line continuation with quotes in Livecode? - livecode

In a Livecode script I have
put "CREATE TABLE containers ( `id` INTEGER NOT NULL, `name` TEXT NOT NULL, `description` TEXT, `location` TEXT, `kind` TEXT NOT NULL, `capacity` INTEGER NOT NULL, PRIMARY KEY(id) )" into tSQL
It would read much better if I could use line continuation as in
put "CREATE TABLE containers (\
`id` INTEGER NOT NULL,\
`name` TEXT NOT NULL,\
`description` TEXT,\
`location` TEXT,\
`kind` TEXT NOT NULL,\
`capacity` INTEGER NOT NULL,\
PRIMARY KEY(id)\
)" into tSQL
but the \ does not seem to work when the line contains double quotes. Is there any other way to accomplist his?

Unfortunately you can't use a line continuation character inside a quoted string, since it is treated as a literal value. You have to close the string and concatenate, like this:
put "CREATE TABLE containers (" & \
"`id` INTEGER NOT NULL," & \
"`name` TEXT NOT NULL," & \
"`description` TEXT," & \
"`location` TEXT," & \
"`kind` TEXT NOT NULL," & \
"`capacity` INTEGER NOT NULL," & \
"PRIMARY KEY(id)" & \
")" into tSQL

Related

How to handle Pipe and escape characters while reading pipe delimited files in PySpark

I have a pipe delimited file. How to handle backslash and pipe inside the content
Here is the input
col1|col2|col3|col4
123|"\|"|""|2020.01.31 12:00:30
456|"\"|""|2020.01.31 12:00:30
678|"|"|""|2020.01.31 12:00:30
I tried with below option
data = spark.read.format("com.databricks.spark.csv")\
.option("inferSchema", "true")\
.option('header','true')\
.option('delimiter','|')\
.option("quote", '"')\
.option("escape","|")\
.option("escape", "\\")\
.option("timestampFormat", "yyyy.mm.dd hh:mm:ss")\
.load('s3://dummybucket/a.csv')
I got output as
col1|col2|col3|col4
123|"\\|"|""|2020-01-31T00:00:30.000Z
456|"\"|\""|2020-01-31T00:00:30.000Z|""
678|"|"|""|2020-01-31T00:00:30.000Z
Expected output
col1|col2|col3|col4
123|"\|"|""|2020-01-31T00:00:30.000Z
456|"\"|""|2020-01-31T00:00:30.000Z
678|"|"|""|2020-01-31T00:00:30.000Z
You have declared escape twice. However, the property can be defined only once for a dataset. You will need to define this only once.
.option("escape","|") \
.option("escape", "\\") \
By default the value for escape will be \ if not defined (link here).
You have defined your quote character as ". An escape character is used to escape a quote character. For example "show this \"" would yield show this " if the quote character was " and escape was \.
For this particular example, you will either need to change your escape to a control character such as # or any value which does not appear before your quote character of ". Hence you can't use | as this appears before a quote on line 1. Also you can't use \ as that appears before quote on line 2.
You have to specify a value for escape as well due to default value being \. This would break line 2 for you.

remove spaces between fields of lines in Unix [duplicate]

This question already has answers here:
How to replace multiple spaces with a single space using Bash? [duplicate]
(3 answers)
Closed 3 years ago.
When I do a desc hive table like below on a Linux terminal CLI.
hive -e "desc hive_db.hive_table"
I get the following output
date string
entity string
key int
id string
direction string
indicator string
account_number string
document_date string
Now I want to redirect the output to a file before doing it I want to remove the spaces between each fields and have just one space between them.
The expected output is below
date string
entity string
key int
id string
direction string
indicator string
account_number string
document_date string
I have tried like below
hive -e "desc hive_db.hive_table" | tr -s " " > abc.txt
The output I get is
date string
entity string
key int
id string
direction string
indicator string
account_number string
document_date string
Th output I get is a close one but I have one space and one tab between each fields in each line
How can I achieve what I want?
Try:
hive -e "desc hive_db.hive_table" | sed -E 's/[[:space:]]+/ /' > abc.txt
[[:space:]]+ matches one or more of any kind of white space (tab, blank, or other including any unicode-defined white space). s/[[:space:]]+/ / replaces that sequence of white space with a single blank.

Cassandra CLI command with cqlsh -e how to declare

In my Cassandra table, it had been created with all columns in Upper case. When we tried to select the columns in cqlsh terminal, we were able to select those columns, but when we tried to pull same query based on the cqlsh -e facing some issue with escaping character.
cqlsh:key1> select "PLAN_ID" ,"A_ADVERTISER_ID" ,"ADVERTISER_NAME" from key1.plan_advertiser where "PLAN_ID" = '382633' and "A_ADVERTISER_ID" = 15019;
PLAN_ID | A_ADVERTISER_ID | ADVERTISER_NAME
---------+-----------------+----------------------
382633 | 15019 | Hanesbrands, Updated
NMH206576286LM:sparklatest0802 KarthikeyanDurairaj$ cqlsh -e 'select "PLAN_ID" ,
"A_ADVERTISER_ID" ,"ADVERTISER_NAME" from key1.plan_advertiser
where "PLAN_ID" = '382633' and "A_ADVERTISER_ID" = 15019'
<stdin>:1:InvalidRequest: Error from server: code=2200 [Invalid query]
message="Invalid INTEGER constant (382633) for "PLAN_ID" of type text"
NMH206576286LM:sparklatest0802 KarthikeyanDurairaj$
cqlsh can be a little tricky in this regard. While it doesn't allow you to escape single quotes, it does allow you to escape double quotes. This works for me:
$ bin/cqlsh -u cassdba -p flynnLives -e "SELECT * FROM stackoverflow.plan_advertiser
where \"PLAN_ID\" = '382633' and \"A_ADVERTISER_ID\" = 15019"
PLAN_ID | A_ADVERTISER_ID | ADVERTISER_NAME
---------+-----------------+----------------------
382633 | 15019 | Hanesbrands, Updated
(1 rows)
In this way, we switch from single quotes to double quotes for the CQL statement, use single quotes for column values, and then escape out the double quotes around the column names.

psql in bash very strange error

I Have a problem with a psql query in bash.
I really don't know why the PSQL understands the value HUB is a Column.
psql -q -A -h Some_host
-U User -d datashema -p 1111 -t -f query.txt -c 'SELECT id, text FROM great_201704 WHERE id = 10 and
text = 'HUB' ;'
ERROR: column "hub" does not exist in great_201704
You read your single quotes as if they nest:
-c 'SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;'
^---------------------------------1--------------------------------^
^-2-^
Bash reads them as two single quoted string with a literal between them:
-c 'SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;'
^------------------------------1----------------------------^
^2-^
This is equivalent to not having single quotes around HUB, which is why psql thinks its a column.
The easiest way to embed one set of quotes in another string is to just use two different types of quotes:
psql -q -A -h Some_host -U User -d datashema -p 1111 -t -f query.txt \
-c "SELECT id, text FROM great_201704 WHERE id = 10 and text = 'HUB' ;"

Cut a special char in c#

Someone know how to cut a string with a SPLIT Method ?
No idea when it comes with ' \ '.
**identitiname = HttpContext.Current.User.Identity.Name;
identitiname *// it has the value FAMILY\ANDRES*
string[] usuario = identitiname.Split( '\' );**
It gives me an error code.
Regards
When we split string by \ then you have to use \\ because \ is used for formatting..
string[] usuario = identitiname.Split( '\\' );

Resources