Skip to content

Commit

Permalink
Improve comments describing row number assertion check. Make passing …
Browse files Browse the repository at this point in the history
…text-separator optional.
  • Loading branch information
m5n committed Nov 28, 2013
1 parent fc2a415 commit 7c62501
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions MySQL.pm
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ sub sql_load_file {
# TODO: how to make MySQL generate an error if varchar data truncation occurs?
my $result = "load data local infile '$file'\n";
$result .= " into table $table_name\n";
$result .= " fields terminated by '$field_separator' optionally enclosed by '$text_separator'\n";
$result .= " fields terminated by '$field_separator'";
$result .= " optionally enclosed by '$text_separator'" if $text_separator;
$result .= "\n";
$result .= " lines terminated by '$line_separator'\n";
$result .= " ignore $ignore_header_lines lines\n" if $ignore_header_lines;
$result .= " (";
Expand Down Expand Up @@ -187,10 +189,11 @@ sub sql_assert_record_count {
# 2. insert the value 2
# 3. insert the record count of the table to be asserted
# 4. remove the record where the value is the assertion value
# case a: if the record count == assertion value, there's now just 1 row in the temporary table (just the value 2)
# case b: if the record count != assertion value, there are 2 rows in the temporary table (the value 2 and the incorrect assertion value)
# case a: if the record count in step 3 == assertion value, there's now just 1 row in the temporary table (just the value 2)
# case b: if the record count in step 3 != assertion value, there are now 2 rows in the temporary table (the value 2 and the incorrect record count value)
# 5. insert the record count of the temporary table
# no error for case a, and a sql error for case b (trying to insert a non-unique value)
# (note this also works if the assertion value happens to == 2)

my $result = "create table tmp (c int unique key);\n";
$result .= "insert into tmp (c) values (2);\n";
Expand Down
7 changes: 4 additions & 3 deletions Oracle.pm
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ sub sql_load_file {
print FILE " APPEND\n"; # Must be APPEND to use PARALLEL option.
print FILE " INTO TABLE $table_name\n";
print FILE " FIELDS TERMINATED BY '$field_separator'\n";
print FILE " OPTIONALLY ENCLOSED BY '$text_separator'\n";
print FILE " OPTIONALLY ENCLOSED BY '$text_separator'\n" if $text_separator;
print FILE " TRAILING NULLCOLS\n"; # To load empty columns, e.g. lines ending in ^^^^.
print FILE " (";
# Need to specify sqlldr data types to get around sqlldr's max char size of 255, as well as read date formats.
Expand All @@ -192,10 +192,11 @@ sub sql_assert_record_count {
# 2. insert the value 2
# 3. insert the record count of the table to be asserted
# 4. remove the record where the value is the assertion value
# case a: if the record count == assertion value, there's now just 1 row in the temporary table (just the value 2)
# case b: if the record count != assertion value, there are 2 rows in the temporary table (the value 2 and the incorrect assertion value)
# case a: if the record count in step 3 == assertion value, there's now just 1 row in the temporary table (just the value 2)
# case b: if the record count in step 3 != assertion value, there are now 2 rows in the temporary table (the value 2 and the incorrect record count value)
# 5. insert the record count of the temporary table
# no error for case a, and a sql error for case b (trying to insert a non-unique value)
# (note this also works if the assertion value happens to == 2)

my $result = "CREATE TABLE tmp (c NUMBER PRIMARY KEY);\n";
$result .= "INSERT INTO tmp (c) VALUES (2);\n";
Expand Down

0 comments on commit 7c62501

Please sign in to comment.