Skip to content
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
@@ -1,10 +1,10 @@
{
"frameworks": {
"net46":{
"net46": {
"dependencies": {
"Antlr4.Runtime": "4.5.3",
"Sql-Server-Rest-Api": "0.2.6"
"Sql-Server-Rest-Api": "0.3.3"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceW
try{
string ConnectionString = ConfigurationManager.ConnectionStrings["azure-db-connection"].ConnectionString;
var sqlQuery = new QueryPipe(ConnectionString);
var tableSpec = new SqlServerRestApi.SQL.TableSpec("sys.objects", "object_id,name,type,schema_id,create_date");
var tableSpec = new SqlServerRestApi.TableSpec("sys","objects", "object_id,name,type,schema_id,create_date");
return await req.CreateODataResponse(tableSpec, sqlQuery);

} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"dependencies": {
"Belgrade.Sql.Client": "0.6.5"
"frameworks": {
"net46": {
"dependencies": {
"Belgrade.Sql.Client": "0.7"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"frameworks": {
"net46": {
"dependencies": {
"Belgrade.Sql.Client": "0.7"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Configuration;
using Belgrade.SqlClient;
using Belgrade.SqlClient.SqlDb;

public static async Task Run(Stream myBlob, string name, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name}");
if(name.EndsWith(".dat")){
string ConnectionString = ConfigurationManager.ConnectionStrings["azure-db-connection"].ConnectionString;
log.Info($"Importing blob\n Name:{name}");
string sql =
@"BULK INSERT Product
FROM '" + name + @"'
WITH ( DATA_SOURCE = 'MyAzureBlobStorage',
FORMATFILE='product.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureBlobStorage',
TABLOCK); ";
log.Info($"SQL query:{sql}");
await (new Command(ConnectionString)).ExecuteNonQuery(sql);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
12.0
7
1 SQLNCHAR 2 100 "" 1 Name SQL_Latin1_General_CP1_CI_AS
2 SQLNCHAR 2 30 "" 2 Color SQL_Latin1_General_CP1_CI_AS
3 SQLMONEY 0 8 "" 3 Price ""
4 SQLNCHAR 2 10 "" 4 Size SQL_Latin1_General_CP1_CI_AS
5 SQLINT 1 4 "" 5 Quantity ""
6 SQLNCHAR 2 8000 "" 6 Data SQL_Latin1_General_CP1_CI_AS
7 SQLNCHAR 2 8000 "" 7 Tags SQL_Latin1_General_CP1_CI_AS
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- 1. INSERT CSV file into Product table
BULK INSERT Product
FROM 'product.csv'
WITH ( DATA_SOURCE = 'MyAzureBlobStorage',
FORMAT='CSV', CODEPAGE = 65001, --UTF-8 encoding
FIRSTROW=2,
TABLOCK);

-- 2. INSERT file exported using bcp.exe into Product table
BULK INSERT Product
FROM 'product.dat'
WITH ( DATA_SOURCE = 'MyAzureBlobStorage',
FORMATFILE='product.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureBlobStorage',
TABLOCK);

-- 3. Read rows from product.dat file using format file and insert it into Product table
INSERT INTO Product WITH (TABLOCK) (Name, Color, Price, Size, Quantity, Data, Tags)
SELECT Name, Color, Price, Size, Quantity, Data, Tags
FROM OPENROWSET(BULK 'product.dat',
DATA_SOURCE = 'MyAzureBlobStorage',
FORMATFILE='product.fmt',
FORMATFILE_DATA_SOURCE = 'MyAzureBlobStorage') as products;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/********************************************************************************
* Note: You can export file and create format file using bcp out command:
*
*>bcp "SELECT Name, Color, Price, Size, Quantity, Data, Tags FROM Product" queryout product.dat -d ProductCatalog -T
*
********************************************************************************/

/********************************************************************************
* 1. SETUP *
********************************************************************************/


/********************************************************************************
* 1.1. OPTIONAL CREDENTIAL SETUP *
* (if data source is not public) *
********************************************************************************/
-- 1.1.1. (optional) Create master key that will encrypt credentials
--
-- Required only if you need to setup CREDENTIAL in 1.1.2.
-- CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'some strong password';

-- 1.1.2. (optional) Create credential with Azure Blob SAS
--
-- CREATE DATABASE SCOPED CREDENTIAL MyAzureBlobStorageCredential
-- WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
-- SECRET = 'sv=2015-12-11&ss=b&srt=sco&sp=rwac&se=2017-02-01T00:55:34Z&st=2016-12-29T16:55:34Z&spr=https&sig=copyFromAzurePortal';
-- NOTE: DO NOT PUT FIRST CHARACTER '?'' IN SECRET!!!



/********************************************************************************
* 1.2. REQUIRE DATA SOURCE SETUP *
* (optionally add credential) *
********************************************************************************/

-- Create external data source with with the roow URL of the Blob storage Account and associated credential (if it is not public).
CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage
WITH ( TYPE = BLOB_STORAGE,
LOCATION = 'https://sqlchoice.blob.core.windows.net/sqlchoice/samples/load-from-azure-blob-storage',
-- CREDENTIAL= MyAzureBlobStorageCredential --> CREDENTIAL is not required if a blob storage is public!
);

/********************************************************************************
* 1.3. CREATE DESTINATION TABLE (if not exists) *
*********************************************************************************/

DROP TABLE IF EXISTS Product;
GO

CREATE TABLE dbo.Product(
Name nvarchar(50) NOT NULL,
Color nvarchar(15) NULL,
Price money NOT NULL,
Size nvarchar(5) NULL,
Quantity int NULL,
Data nvarchar(4000) NULL,
Tags nvarchar(4000) NULL
)
GO