Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Unicode in SQL Server BULK INSERT statements. #152

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ private void importCSVFile(
queryFormatter.addQueryPhrase(destinationTableName);
queryFormatter.addQueryPhrase(" FROM '");
queryFormatter.addQueryPhrase(csvFilePath);
queryFormatter.addQueryPhrase("' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\\n', TABLOCK)");
queryFormatter.addQueryPhrase("' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',', "
+ "ROWTERMINATOR = '\\n', TABLOCK, "
+ "DATAFILETYPE = 'widechar')");
// by specifying FIRSTROW = 2 we skip the header row

System.out.println(queryFormatter.generateQuery());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public String generateQuery() {
addQueryPhrase("',");
finishLine();
addQueryLine(1, "TABLOCK,");
addQueryLine(1, "FIRSTROW=2");
addQueryLine(1, "FIRSTROW=2,");
addQueryLine(1, "DATAFILETYPE = 'widechar'");
addQueryPhrase(0, ")");

return super.generateQuery();
Expand Down
12 changes: 8 additions & 4 deletions rifDatabase/DataLoaderData/SAHSULAND/ms_run_data_loader.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ WITH
(
FIRSTROW=2,
FORMATFILE = '$(pwd)/pop_sahsuland_pop.fmt',
TABLOCK
TABLOCK,
DATAFILETYPE = 'widechar'
);
GO
ALTER TABLE rif_data.POP_SAHSULAND_POP ADD CONSTRAINT pop_sahsuland_pop_pk PRIMARY KEY CLUSTERED(YEAR,AGE_SEX_GROUP,SAHSU_GRD_LEVEL4);
Expand Down Expand Up @@ -275,7 +276,8 @@ WITH
(
FORMATFILE = '$(pwd)/num_sahsuland_cancer.fmt',
TABLOCK,
FIRSTROW=2
FIRSTROW=2,
DATAFILETYPE = 'widechar'
);
GO
ALTER TABLE rif_data.NUM_SAHSULAND_CANCER ADD CONSTRAINT num_sahsuland_cancer_pk PRIMARY KEY CLUSTERED(YEAR,AGE_SEX_GROUP,SAHSU_GRD_LEVEL4,ICD);
Expand Down Expand Up @@ -469,7 +471,8 @@ WITH
(
FORMATFILE = '$(pwd)/covar_sahsuland_covariates3.fmt',
TABLOCK,
FIRSTROW=2
FIRSTROW=2,
DATAFILETYPE = 'widechar'
);
GO
ALTER TABLE rif_data.COVAR_SAHSULAND_COVARIATES3 ADD CONSTRAINT covar_sahsuland_covariates3_pk PRIMARY KEY CLUSTERED(YEAR,SAHSU_GRD_LEVEL3);
Expand Down Expand Up @@ -581,7 +584,8 @@ WITH
(
FORMATFILE = '$(pwd)/covar_sahsuland_covariates4.fmt',
TABLOCK,
FIRSTROW=2
FIRSTROW=2,
DATAFILETYPE = 'widechar'
);
GO
ALTER TABLE rif_data.COVAR_SAHSULAND_COVARIATES4 ADD CONSTRAINT covar_sahsuland_covariates4_pk PRIMARY KEY CLUSTERED(YEAR,SAHSU_GRD_LEVEL4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ WITH
(
FIRSTROW = 2,
FORMATFILE = '$(pwd)/covar_sahsuland_covariates3.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -141,7 +142,8 @@ WITH
(
FIRSTROW = 2,
FORMATFILE = '$(pwd)/covar_sahsuland_covariates4.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -213,7 +215,8 @@ WITH
(
FIRSTROW = 2,
FORMATFILE = '$(pwd)/num_sahsuland_cancer.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -299,7 +302,8 @@ WITH
(
FIRSTROW = 2,
FORMATFILE = '$(pwd)/pop_sahsuland_pop.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -406,4 +410,4 @@ GO
QUIT

--
-- Eof
-- Eof
12 changes: 8 additions & 4 deletions rifDatabase/GeospatialData/tileMaker/mssql_SAHSULAND.sql
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ FROM '$(pwd)/sahsu_grd_level1.csv' -- Note use of pwd; set via -v pwd="%cd%" in
WITH
(
FORMATFILE = '$(pwd)/mssql_sahsu_grd_level1.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -2115,7 +2116,8 @@ FROM '$(pwd)/sahsu_grd_level2.csv' -- Note use of pwd; set via -v pwd="%cd%" in
WITH
(
FORMATFILE = '$(pwd)/mssql_sahsu_grd_level2.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -3395,7 +3397,8 @@ FROM '$(pwd)/sahsu_grd_level3.csv' -- Note use of pwd; set via -v pwd="%cd%" in
WITH
(
FORMATFILE = '$(pwd)/mssql_sahsu_grd_level3.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar'
);
GO

Expand Down Expand Up @@ -4765,7 +4768,8 @@ FROM '$(pwd)/sahsu_grd_level4.csv' -- Note use of pwd; set via -v pwd="%cd%" in
WITH
(
FORMATFILE = '$(pwd)/mssql_sahsu_grd_level4.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down
33 changes: 22 additions & 11 deletions rifDatabase/GeospatialData/tileMaker/rif_mssql_SAHSULAND.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,8 @@ FROM '$(pwd)\mssql_lookup_sahsu_grd_level1.csv' -- Note use of pwd; set via -v p
WITH
(
FORMATFILE = '$(pwd)\mssql_lookup_sahsu_grd_level1.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -1115,7 +1116,8 @@ FROM '$(pwd)\mssql_lookup_sahsu_grd_level2.csv' -- Note use of pwd; set via -v p
WITH
(
FORMATFILE = '$(pwd)\mssql_lookup_sahsu_grd_level2.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -1125,7 +1127,8 @@ FROM '$(pwd)\mssql_lookup_sahsu_grd_level3.csv' -- Note use of pwd; set via -v p
WITH
(
FORMATFILE = '$(pwd)\mssql_lookup_sahsu_grd_level3.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -1135,7 +1138,8 @@ FROM '$(pwd)\mssql_lookup_sahsu_grd_level4.csv' -- Note use of pwd; set via -v p
WITH
(
FORMATFILE = '$(pwd)\mssql_lookup_sahsu_grd_level4.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -1394,7 +1398,8 @@ FROM '$(pwd)\mssql_hierarchy_sahsuland.csv' -- Note use of pwd; set via -v pwd="
WITH
(
FORMATFILE = '$(pwd)\mssql_hierarchy_sahsuland.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -1795,7 +1800,8 @@ FROM '$(pwd)\mssql_geometry_sahsuland.csv' -- Note use of pwd; set via -v pwd="%
WITH
(
FORMATFILE = '$(pwd)\mssql_geometry_sahsuland.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -2206,7 +2212,8 @@ FROM '$(pwd)\mssql_adjacency_sahsuland.csv' -- Note use of pwd; set via -v pwd="
WITH
(
FORMATFILE = '$(pwd)\mssql_adjacency_sahsuland.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down Expand Up @@ -4825,7 +4832,8 @@ FROM '$(pwd)\mssql_t_tiles_sahsu_grd_level1.csv' -- Note use of pwd; set via -v
WITH
(
FORMATFILE = '$(pwd)\mssql_t_tiles_sahsu_grd_level1.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -4846,7 +4854,8 @@ FROM '$(pwd)\mssql_t_tiles_sahsu_grd_level2.csv' -- Note use of pwd; set via -v
WITH
(
FORMATFILE = '$(pwd)\mssql_t_tiles_sahsu_grd_level2.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -4867,7 +4876,8 @@ FROM '$(pwd)\mssql_t_tiles_sahsu_grd_level3.csv' -- Note use of pwd; set via -v
WITH
(
FORMATFILE = '$(pwd)\mssql_t_tiles_sahsu_grd_level3.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand All @@ -4888,7 +4898,8 @@ FROM '$(pwd)\mssql_t_tiles_sahsu_grd_level4.csv' -- Note use of pwd; set via -v
WITH
(
FORMATFILE = '$(pwd)\mssql_t_tiles_sahsu_grd_level4.fmt', -- Use a format file
TABLOCK -- Table lock
TABLOCK, -- Table lock
DATAFILETYPE = 'widechar' -- Handle Unicode
);
GO

Expand Down
Binary file not shown.
Binary file modified rifDatabase/SQLserver/Version1_RH_2014/complete_script_23OCT.sql
Binary file not shown.
39 changes: 26 additions & 13 deletions rifDatabase/SQLserver/installation/rif40_import_sahsuland.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ FROM '$(path)\SQLserver\sahsuland_dev\rif_data\rif40_columns.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO
BULK
Expand All @@ -91,7 +92,8 @@ FROM '$(path)\SQLserver\sahsuland_dev\rif_data\rif40_tables_and_views.txt'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand Down Expand Up @@ -172,7 +174,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_version.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -182,7 +185,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_age_groups.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO
BULK
Expand All @@ -191,7 +195,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_age_group_names.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -201,7 +206,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_reference_tables.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -211,7 +217,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_outcomes.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -221,7 +228,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_health_study_themes.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO
/*
Expand Down Expand Up @@ -273,7 +281,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_outcome_groups.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -283,7 +292,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_table_outcomes.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -307,7 +317,8 @@ FROM '$(path)\Postgres\sahsuland\data\t_rif40_parameters.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)

--
Expand All @@ -321,7 +332,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_triggers_mssql.csv'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO

Expand All @@ -331,7 +343,8 @@ FROM '$(path)\Postgres\sahsuland\data\rif40_predefined_groups_mssql.csv'
WITH
(
FIELDTERMINATOR = '|',
ROWTERMINATOR = '0x0a'
ROWTERMINATOR = '0x0a',
DATAFILETYPE = 'widechar'
)
GO
/*
Expand Down
2 changes: 1 addition & 1 deletion rifNodeServices/dataLoader/tile-maker_fileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function shpConvertInput(files, shpConvertInputCallback) {
data=fileContainedInZipFile.asArrayBuffer();
}
else {
console.log("asyncSeriesIteree() WARNING! Ignoring[" + ZipIndex + "]: " + zipName + "; size: " +
console.log("asyncSeriesIteree() WARNING! Ignoring extension: " + zipExt + "; index: " + ZipIndex + ": " + zipName + "; size: " +
fileContainedInZipFile._data.length || fileContainedInZipFile._data.uncompressedSize + " bytes");
// zipMsg+="<br>Zip file[" + noZipFiles + "]: file: " + zipName +
// "; expanded: " + unzipPct +
Expand Down
Loading