I keep running into the error message on a Teradata fast load
Error: Quote strings required for name
I have my script set to:
SET RECORD VARTEXT "|"QUOTE YES '"';
sample data set:
"ITEM"|"DIMEN_TYPE"|"HGT"|"WID"|"LENT"|"WGHT"
123456|"D"|4.25|5.25|0.5|0.25
Any idea what I am missing? Thanks!
I modified the source data from a pipe to tab removed the quote portion
SET RECORD VARTEXT DELIMITER " ";
and added
SET SESSION CHARSET “UTF8”;
This combination seemed to fix the issue.
Related
I'm trying to insert some information to MySQL with Pascal, but when I run the program I get the error
unknown column 'mohsen' in field list
This is my code
procedure TForm1.Button1Click(Sender: TObject);
var
aSQLText: string;
aSQLCommand: string;
namee:string;
family:string;
begin
namee:='mohsen';
family:='dolatshah';
aSQLText:= 'INSERT INTO b_tbl(Name,Family) VALUES (%s,%s)';
aSQLCommand := Format(aSQLText, [namee, family]);
SQLConnector1.ExecuteDirect(aSQLCommand);
SQLTransaction1.Commit;
end;
How can I solve this problem?
It's because your
VALUES (%s,%s)
isn't surrounding the namee and family variable contents by quotes. Therefore, your back-end Sql engine thinks your mohsen is a column name, not a value.
Instead, use, e.g.
VALUES (''%s'',''%s'')
as in
Namee := 'mohsen';
Family := 'dolatshah';
aSQLText:= 'INSERT INTO b_tbl(Name,Family) VALUES (''%s'',''%s'')';
aSQLCommand := Format(aSQLText,[namee,family]);
In the original version of my answer, I explained how to fix your problem by "doubling up" single quotes in the Sql you were trying to build, because it seemed to me that you were having difficulty seeing (literally) what was wrong with what you were doing.
An alternative (and better) way to avoid your problem (and the one I always use in real life) is to use the QuotedStr() function. The same code would then become
aSQLText := 'INSERT INTO b_tbl (Name, Family) VALUES (%s, %s)';
aSQLCommand := Format(aSQLText, [QuotedStr(namee), QuotedStr(family)]);
According to the Online Help:
Use QuotedStr to convert the string S to a quoted string. A single quote character (') >is inserted at the beginning and end of S, and each single quote character in the string is >repeated.
What it means by "repeated" is what I've referred to as "doubling up". Why that's important, and the main reason I use QuotedStr is to avoid the Sql db-engine throwing an error when the value you want to send contains a single quote character as in O'Reilly.
Try adding a row containing that name to your table using MySql Workbench and you'll see what I mean.
So, not only does using QuotedStr make constructing SQL statements as strings in Delphi code less error-prone, but it also avoid problems at the back-end, too.
Just in case this will help anybody else I had the same error when I was parsing a python variable with a sql statement and it had an if statement in i.e.
sql="select bob,steve, if(steve>50,'y','n') from table;"
try as I might it coming up with this "unknown column y" - so I tried everything and then I was about to get rid of it and give it up as a bad job until I thought I would swap the " for ' and ' for "..... Hoooraaahh it works!
This is the statement that worked
sql='select bob,steve, if(steve>50,"y","n") from table;'
Hope it helps...
To avoid this sort of problem and SQL injection you should really look into using SQL parameters for this, not the Pascal format statement.
try to upload CSV data with a case statement in the query, but the following error appears:
cypher:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
MATCH(a:test_t{tid:line.pid})
CASE
WHEN line.key !='NA' THEN
WITH split(line.key,",") as name
UNWIND name as x
MERGE(k:test_key{key_term:toLower(x)})
MERGE(a)-[:contains]->(k)
END
Error
Neo.ClientError.Statement.SyntaxError: Invalid input 'S': expected 'l/L' (line 5, column 3 (offset: 137))
"CASE"
Can anyone help me?
The CASE clause does not support embedding other Cypher clauses (but it can invoke functions). In fact, a CASE clause is not actually needed for your use case.
This query should work (the :auto at the beginning is needed in neo4j 4.0+):
:auto USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line FIELDTERMINATOR ';'
WITH line
WHERE line.key <> 'NA'
MATCH (a:test_t {tid: line.pid})
UNWIND split(line.key, ',') as x
MERGE (k:test_key {key_term: TOLOWER(x)})
MERGE (a)-[:contains]->(k)
This query filters out all unwanted lines as soon as they are obtained from the file. Reducing the number of rows of data being worked on as early as possible is good practice.
Also, you have a second issue. Your data file cannot use the comma as both the (default) field terminator AND as the delimiter between your x values.
To resolve this ambiguity, the above query chose to use the FIELDTERMINATOR ';' option to specify that the ";" character will be used as the field terminator. A sample data file would look like this:
pid;key
123;NA
234;Foo,Bar
345;Bar,Baz
456;NA
567;Baz
You are using the CASE incorrectly. You cannot have update clauses inside of a CASE statement. Instead you can use a WHERE clause to filter the rows of the file. For instance, adding WHERE line.key != 'NA' while processing the file befor you move onto the update will work. Something like this should fit the bill.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
MATCH (a:test_t {tid: line.pid})
WITH line
WHERE line.key <> 'NA'
WITH split(line.key, ",") as name
UNWIND name as x
MERGE (k:test_key {key_term: toLower(x)})
MERGE (a)-[:contains]->(k)
It looks like,from your logic you could even move the test up above the MATCH. So this might be better (fewer unecessary matches).
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///test.csv' as line
WITH line
WHERE line.key <> 'NA'
MATCH (a:test_t {tid: line.pid})
WITH split(line.key, ",") as name
UNWIND name as x
MERGE (k:test_key {key_term: toLower(x)})
MERGE (a)-[:contains]->(k)
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 trying to set the delimiter in a Fastload to \001 with no success.
Anybody know if this is possible?
SET record vartext "\001";
It is not possible.
Teradata Fastload Reference, Chapter 3: Teradata Fasload Commands, Section 'SET RECORD'
The delimiter can be a single or multi-character sequence (or string)
...
No control character other than a tab character can be used in a
delimiter.
I have this error appearing above the pages of my Drupal site:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 32
bytes in C:\xampp\htdocs\irbid\includes\bootstrap.inc on line 559
What does this error mean and how can I fix it ?
This is caused by a corrupt entry in the variables table. The value of this table is a serialized php value.
See those for more information on what a serialize value is:
http://php.net/serialize
http://php.net/unserialize
Basically, if one of the value was changed by hand, it can cause something like this.
For example, the default value of the Anonymous variable is:
+-----------+------------------+
| name | value |
+-----------+------------------+
| anonymous | s:9:"Anonymous"; |
+-----------+------------------+
If you change the value to s:9:"Some other value"; then this will cause a problem.
The first character is the type of value. The value s means STRING. Then the colon followed by a number indicate a length. In this case, the word Anonymous is exactly 9 characters. But there is more than 9 characters for Some other value. There are 16 characters in that value, so the correct way would be s:16:"Some other value";.
If someone put the value not serialized (without the s:9:"";) then it would also cause this problem.
I had this very problem in the past. I added some debug code to find out what variable was causing this. I added something like this:
$value = unserialize($variable->value);
if ($value === FALSE) {
watchdog('unserialize', $variable->name);
}
I put this code right before the line causing the error and then I generated the error one more time and I went to the "Recent Log Entries" in Drupal admin http://yoursite.com/admin/reports/dblog and filtered by the type unserialize.
Once I had the name of the variable, I would connect to the database and perform this query:
SELECT * FROM variable WHERE name='name-goes-here';
and I put the name that I found in the logs.
I look at the value and figure out why it is causing this error and then fix the value.
I hope this helps.
My issue was related to UTF-8. String shorter - character-wise (because contained UTF-8) but unserialized expecting longer one.
Solution:
/**
* serialize utf8 values
*
* #param $serial_str
* input sting serialize.
*
* #return (array) $out
* serialize values
*
* #author Mudassar Ali <sahil_bwp#yahoo.com>
*/
function mb_unserialize($serial_str) {
$return = '';
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str);
$return = unserialize($out);
if ($return === FALSE) {
watchdog('unserialize', $out);
} else {
return $return;
}
}
and
$module->info = mb_unserialize($module->info);
instead of
$module->info = unserialize($module->info);
Make sure your default character set on the server to be UTF8, and default collation to be utf8_general_ci. This is a setting in mysql.ini. Here's the nuclear option.
[mysqld]
default-character-set = utf8
character-set-server = utf8
collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
[client]
default-character-set = utf8
[mysql]
default-character-set = utf8
[mysqldump]
default-character-set = utf8
and also make sure your DB is also
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
To find out the potential variables that might be causing the issue, find the one that is broken, and delete it from the database.
SELECT name, LENGTH( value ) , value FROM variable WHERE LENGTH( value ) = "32";
DELETE FROM variable WHERE name = "broken_variable_name";
Why this error is thrown
This error is caused when an entry in Drupal's variables tables isn't in the right format. It often occurs if your host automatically installs your Drupal installation and doesn't do it right, (Like my host likes to do) or if variables haven't been created properly.
Identify the malformed variable
I made a module but you could just write this into a PHP filter input field, like a node or block (obviously, you'd need the core module "PHP Filter" turned on).
This code will output the content of the variables table, so don't do this on a production site:
drupal_set_message(db_query('SELECT name, value FROM
{variable}')->fetchAllKeyed() );
Then you can just go through the list and find the one that is malformed.
How do I know which variable is malformed
Each row is in one of these formats. Each has 2 parameters separated by colons. The 2nd and 3rd fields are values and vary depending on the variable name, as long as they're in approximately one of these formats, they should be ok:
s:16:"this is a string"
s is for String. 16 is the number of characters long the string is. The third parameter is the value in double quotes.
i:10
i is for Integer. 10 is the value of the integer.
b:0
b is for booleen. 0 is the value
a:0:{}
a is for array. 0 is the number of elements and the third parameter is the array. The array may contain any of the above data types (even another array).
The variable that isn't in one of the above formats is malformed.
Fixing the malformed variable
You should be able to isolate the problem and if it's a variable like "site_name" or "site_mail" you can fix this by updating the configuration page where that variable is set (eg.Site Information). If the malformed variable isn't one you recognise:
Put a line of code like this into a module or PHP filter input.
set_variable('the_name_of_the_malformed_variable','the_value_you_think_it_should_be');
Run it once and then remove, your error should be fixed.
Follow the above at your own risk. If you have problems, leave a comment below.
I received this error after (during?) a core update of drupal.
Notice: unserialize(): Error at offset 11 of 35 bytes in variable_initialize() (line936 of /var/www/vhosts/3/101684/webspace/siteapps/Drupal-12836/htdocs/includes/bootstrap.inc).
I installed the variable check module (http://drupal.org/project/variablecheck) which identified the bad value:
update_notify_emails a:1:{i:0;s:26:"user#email.com";}
But this is indicating that the function is expecting an array, not just a string so I couldn't just set a new value with
set_variable('the_name_of_the_malformed_variable','the_value_you_think_it_should_be');
When I checked the value table in the mysql db but the data value was a blob and I couldn't edit it. Not knowing what module set that value and what might break if I simply deleted it I decided to try "re-setting" the array to clear it out.
Google told me that "update_notify_emails" is called in the update module into modules, clicked congfigure for Update Manager
and edited the value for "E-mail addresses to notify when updates are available" (mine was blank). Since the error indicated it was expecting both an int and a string I also flipped the setting on "Only security updates" so that value was passed in as well. Clicked save and error went away.