I execute: sqlite3 -init mydata.sql mydb with the following as the only line in mydata.sql:
DROP TABLE IF EXISTS [Album];
I get the following error:
Error: near line 1: near "DROP": syntax error
I've whittled the input file to virtually nothing and I always get this syntax error message no matter what command I enter and always on line 1. It looks like it thinks there's some unusual character but I can's see what it could be. Any thoughts?
If you use Notepad++ or other similar text editor, enable showing all symbol.
In Notepad++, view->show symbol->Show All characters
Also check Encoding of this file (Menu->Encoding). You might want to forcefully change encoding to ANSI/UTF-8 (Menu->Encoding->Convert to ANSI).
I had the same error with the Chinook database and SQLite version 3.19.3, so I opened the SQL file (Chinook_Sqlite_AutoIncrementPKs.sql) with Sublime Text and save it like UTF-8 (to eliminate the BOM indicator).
Related
I have a corrupted sqlite file. If I trí to open it, I get this error:
Error: database disk image is malformed
I tried to run .recover, like this:
sqlite3 corrupted.db ".recover" | sqlite3 recovered.db
I was able to open recovered.db, and almost everything is there, but the accented characters are replaced with ??, for example:
Original: Pes jí bagetu
Restored: Pes j?? bagetu
It is unlikely, but possible, that the original file is not utf8 encoded.
If I run .dump, and produce an sql file with insert statement, then I don't experiene this issue. The accented charecters are displayed correctly in the dump.sql. But in this case, less than half of the database was exported, so I prefer .recover.
What do I wrong? The correct characters are there, as the dump shows, but for some reason, they are lost during the export.
I have a CSV file and I want to remove the all line feeds (LF or \n) which are all coming in between the double quotes alone.
Can you please provide me an Unix script to perform the above task. I have given the input and expected output below.
Input :
No,Status,Date
1,"Success
Error",1/15/2018
2,"Success
Error
NA",2/15/2018
3,"Success
Error",3/15/2018
Expected output:
No,Status,Date
1,"Success Error",1/15/2018
2,"Success Error NA",2/15/2018
3,"Success Error",3/15/2018
I can't write everything for you, as I am not sure about your system as well as which bash version that is running on it. But here are a couple of suggestions that you might want to consider.
https://www.unix.com/shell-programming-and-scripting/31021-removing-line-breaks-shell-variable.html
https://www.unix.com/shell-programming-and-scripting/19484-remove-line-feeds.html
How to remove carriage return from a string in Bash
https://unix.stackexchange.com/questions/57124/remove-newline-from-unix-variable
Remove line breaks in Bourne Shell from variable
https://unix.stackexchange.com/questions/254644/how-do-i-remove-newline-character-at-the-end-of-file
https://serverfault.com/questions/391360/remove-line-break-using-awk
Consider this:
> scr<-paste("INSERT INTO ques2_log (freeze_time) value(",sQuote(now()),")")
> scr
#> "INSERT INTO ques2_log (freeze_time) value( ‘2017-06-13 23:46:16’ )"
If we feed this simple SQL script into a MySQL DB as follows:
dbExecute(db,scr1)
The MySQL DB throws the following error:Error in .local(conn, statement, ...) : could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '��2017-06-13 23:44:13’ )' at line 1
I have tested the SQL script by typing by hand and it works.
It is also clear that the single quote is the unexpected character.
I looked up some online articles on character encoding and tried
enc2utf8(scr) before feeding to the DB through RMySQL commands. No effect. Same error.
I also read this and ran
ALTER DATABASE ques2_log CHARACTER SET utf8 COLLATE utf8_general_ci;
But the error remains.
Just use regular single quotes, as in:
paste0("'",date(),"'")
sQuote produces distinct left and right "smart" quotes, as documented in ?sQuote:
Single or double quote text by combining with appropriate single or
double left and right quotation marks.
...and additionally, the documentation makes clear that the intended purpose of this function is for formatting text for displaying user facing messages on screen:
The purpose of the functions is to provide a simple means of markup
for quoting text to be used in the R output, e.g., in warnings or
error messages.
So it generally shouldn't be used for processing text to be used programmatically.
I'm getting the following when I try to read in a fixed width text file using read.fwf.
Here is the output:
invalid multibyte string at 'ETE<52> O 19950207 19031103 537014290 7950 WILLOWS RD
Here are the most relevant lines of code
fieldWidths <- c(10,50,30,40,6,8,8,9,35,30,9,2)
colNames <- c("certNum", "lastN", "firstN", "middleN", "suffix", "daDeath", "daBirth", "namesSSN", "namesResStr", "namesResCity", "namesResZip", "namesStCode")
dmhpNameDF <- read.fwf(fileName, widths = fieldWidths, col.names=colNames, sep="", comment.char="", quote="", fileEncoding="WINDOWS-1258", encoding="WINDOWS-1258")
I'm running R 3.1.1 on Mac OSX 10.9.4
As you can see, I've experimented with specifying alternative encodings, I've tried latin1 and UTF-8 as well as WINDOWS-1250 through 1258
When I read this file into Excel or Word, or TextEdit everything looks good in general. By using the error message text I can id the offending line (row) of text is row number 5496, and upon inspection, I can see that the offending character shows up as an italic looking letter 'f' Searching for that character reveals that there are about 4 instances of it in this file. I have many such files to process so going through one by one to delete the offending character is not a good solution.
So far, the offending character always shows up in a name field, which is good for me as I don't actually want the name data from this file it is of no interest. If it were a numeric field that was corrupted then I'd have to toss out the row.
Since Word and Excel can read the file (apparently substituting the offending character for italic 'f', surely there must be a way to read it in with R, but I've not figured out a solution. I have searched through the many examples of questions related to "invalid multibyte string", but have not found any info that resolved my problem.
My goal is to be able to read in the data either ignoring this "character error" or substituting the offending character with something else.
Unfortunately the file in question contains sensitive information so I can not post a copy of it for people to play with.
Thanks
I wanted to validate my Website for example with http://validator.w3.org but I always get the following error:
Sorry, I am unable to validate this document because on line 11 it
contained one or more bytes that I cannot interpret as utf-8 (in other
words, the bytes found are not valid values in the specified Character
Encoding). Please check both the content of the file and the character
encoding indication. The error was: utf8 "\xFC" does not map to
Unicode
Does anybody know where I can locate/get rid of the error?
open the css-file with your favorite text editor.
There, switch the encoding to UTF8.
Goto line 11 and look for strange looking symbols.
Delete/replace them.