SQlite error while updating the table - database

I am reading data from a table and updating into other table in SQLite. while reading it is not showing any error. But while it is updating it is showing error because the text i am going to update contains "You're" it is showing error for 're--> this apps' re. Any way to update with this special character?

Insert another single quote after You' so that the text becomes "You''re"
http://sqlite.org/lang_expr.html
A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal. C-style escapes using the backslash character are not supported because they are not standard SQL.

Related

Copy into CSV from Snowflake to S3 encloses all fields in quotes, not just the ones with commas

I'm attempting to copy out from a Snowflake table to a CSV on S3 using the "copy into" command.
I noticed that using the following parameters in my copy into statement leads to ALL fields in the entire CSV file being enclosed in double quotes.
file_format=(type=csv compression=none field_optionally_enclosed_by='"' empty_field_as_null=false null_if='' trim_space=true field_delimiter=',') header=true overwrite=true single=true;
Is this expected behavior for the field_optionally_enclosed_by option? I thought that just the fields containing commas in the value would be enclosed by "", but all fields in the full file are enclosed.
Is there another option to see the output that I want? I'd like just the fields containing a comma in the value to be enclosed, but the rest not enclosed.
That's expected behaviour as it's explained here:
https://docs.snowflake.com/en/user-guide/data-unload-considerations.html#empty-strings-and-null-values
FIELD_OPTIONALLY_ENCLOSED_BY = 'character' | NONE
Use this option to
enclose strings in the specified character: single quote ('), double
quote ("), or NONE.
The same parameter is also used when ingesting data, this is why its name is "FIELD_OPTIONALLY_ENCLOSED_BY". When you use this parameter on loading, it doesn't expect all values are enclosed by this character, but they may be enclosed optionally.
Of course, there could be a smarter way to apply this parameter. For example, when the data contains the field_delimiter character, it could be enclosed. This could be a good feature request.

Varchar fields containing a single double quote get exported with two double quotes from snowflake web UI

I have a table with a single Varchar column and a row with value A”B”C .
While downloading it from snowflake UI as a CSV file the result shows A””B””C
.
In this case if you are using Data Unloading feature, you need to use File format in the copy into statement.
In the file format you need to use the option "FIELD_OPTIONALLY_ENCLOSED_BY "
Ref - https://docs.snowflake.com/en/user-guide/data-unload-considerations.html#empty-strings-and-null-values
When a field contains this character, escape it using the same character. For example, if the value is the double quote character and a field contains the string "A", escape the double quotes as follows: ""A"".

Changing .csv delimiter on ADF

I am trying to load a .csv table to MS SQL Server via Azure Data Factory, but I have a problem with the delimiter (;) since it appears as a character in some of the values included in some columns.
As a result, I get an error saying in the details "found more columns than expected column count".
Is there any way to change the delimiter directly on ADF before/while loading the .csv table (ex.: making it from ";" to "|||")?
Thanks in advance!
I have a problem with the delimiter (;) since it appears as a
character in some of the values included in some columns.
As you have quoted that your delimiter is ; but it is occurring as a character in some of the columns which means that there is no specific pattern of the occurrence. Hence, it is not possible in ADF.
The recommendation is to write a program using any preferred language (like python) which will iterate each row from the dataset and write a logic to replace the delimiter to ||| or you can also remove the unrequired ; and append the changes in new file. Later you can ingest this new file in ADF.

How do you escape strings for SQLite table names in c?

How do you escape strings for SQLite table names in c?
I find a document, but it do not tell me the detail https://www.sqlite.org/lang_keywords.html
And this document says that sql is end with '\x00' https://www.sqlite.org/c3ref/prepare.html
Here is the similar question in python: How do you escape strings for SQLite table/column names in Python?
Identifiers should be wrapped in double quotes if they need escaping, with all double quotes in them escaped by doubling up the quotes. bad"name" needs to become "bad""name" to be used in a SQL statement.
Sqlite comes with custom versions of *printf() functions that include formats for escaping sql identifiers and strings (Which use single quotes in SQL). The one that does the escaping of double quotes for identifiers is %w:
char *sanitized_ddl = sqlite3_mprintf("CREATE TABLE \"%w\"(\"%w\", \"%w\");",
"bad\"name", "foo bar", "baz");
Ideally, though, you're not going to use table or column names that need escaping, but it's good practice to escape user-supplied names to help protect against SQL injection attacks and the like.
Example:
example to 'example'
'a to '''a'
Detail:
Do not use the byte value 0 in the string.It will return an error like unrecognized token: "'" even if you pass the correct zSql len to sqlite3_prepare_v2().
Replace ' to '' in the string, add ' to the start and the end to the string. ' is single quote (byte 39).
It is not recommend to use invalid utf8 string. The string do not need to be valid utf8 string according to the parse code in sqlite3 version 3.28.0 . I have tested that invalid utf8 string can use as table name, but the document of sqlite3_prepare_v2() says you need SQL statement, UTF-8 encoded
I have write a program to confirm that any byte list with len 1,2 without byte value 0 in it, can use as the table name, and the program can read value from that table, can list the table from the SQLITE_MASTER table in sqlite3 version 3.28.0.

Import CSV data into SQL Server

I have data in the csv file similar to this:
Name,Age,Location,Score
"Bob, B",34,Boston,0
"Mike, M",76,Miami,678
"Rachel, R",17,Richmond,"1,234"
While trying to BULK INSERT this data into a SQL Server table, I encountered two problems.
If I use FIELDTERMINATOR=',' then it splits the first (and sometimes the last) column
The last column is an integer column but it has quotes and comma thousand separator whenever the number is greater than 1000
Is there a way to import this data (using XML Format File or whatever) without manually parsing the csv file first?
I appreciate any help. Thanks.
You can parse the file with http://filehelpers.sourceforge.net/
And with that result, use the approach here: SQL Bulkcopy YYYYMMDD problem or straight into SqlBulkCopy
Use MySQL load data:
LOAD DATA LOCAL INFILE 'path-to-/filename.csv' INTO TABLE `sql_tablename`
CHARACTER SET 'utf8'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"'
IGNORE 1 LINES;
The part optionally enclosed by '\"', or escape character and quote, will keep the data in the first column together for the first field.
IGNORE 1 LINES will leave the field name row out.
UTF8 line is optional but good to use if names have diacritics, like in José.

Resources