Is there a way to declare dependencies inside a u-sql database project? - u-sql

Introduction and problem description
We are developing a Datalake Analytics solution. We have been using regular U-SQL projects, which are good, but you are left having to work out the packaging and deployment.
So we gave a try to U-SQL Database projects. In theory they are far better and well suited for what we want.
We created a database project that contains so far:
Some Table Types
Some TVFs that receive and / or return some of those table types
Some Procedures that receive and / or return some of those table types
It builds from visual studio, and I can see the usqldbpack output. So far, so good. When I try to deploy it, it always fails with the cryptic message
Deployment failed with Deployment failed with exception 'Failed to deploy DDL script, SDK helper app return failure '-1'' -> Failed to deploy DDL script, SDK helper app return failure '-1'
Then I checked the log, and I see things like
*** Error : (9,59) 'Type 'DatabaseProject1.dbo.MyTableType' does not exist.'
*** Compile failed !
Then I saw the ddl.usql generated by the project, and the Table Type is below the functions that use it. So it is no wonder that it fails.
So I guess there should be a way to let the project know that a TVF is depending on a Table Type, so that it can build the script right.
Is there a way?
Steps to reproduce the issue
Create inside Visual Studio a U-SQL Database Project
Create a Table Type, named MyTableType, with the following code
CREATE TYPE IF NOT EXISTS [dbo].[MyTableType]
AS TABLE
(
[id] string,
[name] string
);
Create a Procedure, named MyProcedure, with the following code
CREATE PROCEDURE IF NOT EXISTS [dbo].[MyProcedure](#table dbo.MyTableType)
AS
BEGIN
OUTPUT #table
TO "/Output/ReferenceGuide/DDL/Procedure/MyTable.csv"
USING Outputters.Csv();
END;
Build the solution. It will build without any issue
Deploy the database, it will fail
Check the log, it will say
*** Error : (9,59) 'Type 'DatabaseProject1.dbo.MyTableType' does not exist.'
*** Compile failed !

Related

ON CONFLICT(id) DO UPDATE SET does not work for FireDAC in DELPHI 10.3.1

After attaching the second database I tried to insert and update data in the table of the first database using ON CONFLICT(id) DO UPDATE. Field id is the primary key for the first table.
FDQuery1.EXECSQL('ATTACH ''D:\Update2019.DB'' AS DBUpdate');
FDQuery1.SQL.Text:=
'INSERT INTO acts (id,title) SELECT id,title FROM DBUpdate.acts'+
' WHERE (DBUpdate.acts.id >100)'+
' ON CONFLICT(id) DO UPDATE SET'+
' title=excluded.title;'
FDQuery1.ExecSQL;
I get error message: "ERROR near "ON":syntax error"
When I removed WHERE (DBUpdate.acts.id >100 condition
the error message AS: "ERROR near "DO":syntax error".
The same query works fine in SQLITESTUDIO.
As correctly indicated in comments, SQLite that your application uses does not support this syntax. You will need to use newer version of SQLite. To do this, follow the Dynamic linking paragraph of FireDAC SQLite connection topic, otherwise Delphi builds your FireDAC application with statically linked SQLite objects of the version distributed with it (which makes your application dependent on such SQLite version no matter what SQLite DLLs are all around).
Just don't forget the most important part of this task; modifying the FireDAC.inc include file to use dynamic linking. If you don't want to break your Delphi setup source folder, copy for example all the FireDAC modules somewhere else, add them into the build search path of your project, and modify the FireDAC.inc include file there.

how can sqlit3 be upgraded in windows 10 for delphi 10.3.1 [duplicate]

After attaching the second database I tried to insert and update data in the table of the first database using ON CONFLICT(id) DO UPDATE. Field id is the primary key for the first table.
FDQuery1.EXECSQL('ATTACH ''D:\Update2019.DB'' AS DBUpdate');
FDQuery1.SQL.Text:=
'INSERT INTO acts (id,title) SELECT id,title FROM DBUpdate.acts'+
' WHERE (DBUpdate.acts.id >100)'+
' ON CONFLICT(id) DO UPDATE SET'+
' title=excluded.title;'
FDQuery1.ExecSQL;
I get error message: "ERROR near "ON":syntax error"
When I removed WHERE (DBUpdate.acts.id >100 condition
the error message AS: "ERROR near "DO":syntax error".
The same query works fine in SQLITESTUDIO.
As correctly indicated in comments, SQLite that your application uses does not support this syntax. You will need to use newer version of SQLite. To do this, follow the Dynamic linking paragraph of FireDAC SQLite connection topic, otherwise Delphi builds your FireDAC application with statically linked SQLite objects of the version distributed with it (which makes your application dependent on such SQLite version no matter what SQLite DLLs are all around).
Just don't forget the most important part of this task; modifying the FireDAC.inc include file to use dynamic linking. If you don't want to break your Delphi setup source folder, copy for example all the FireDAC modules somewhere else, add them into the build search path of your project, and modify the FireDAC.inc include file there.

How to build sqlite VFS into the library

I am trying to compile SQLite into a library which another application is then going to link against. I am not able to compile SQLite directly into that application for reasons which are beyond the scope of this question.
However, I need a VFS to be available which by default is not. In trying to figure out how to get this working I am trying to get the vfstrace shim to be made available to the application which is linking to SQLite. This will easily prove that it is working as I can log SQLite VFS activity from the shim and see that it is actually being used when the application calls SQLite.
How do I do this? All the examples I have found show the case of when you have a source file (such as shell.c) and you compile it, sqlite3.c and test_vfstrace.c to produce an executable. However, I do not have this luxury. I could compile sqlite.c and test_vfstrace.c and generate the libsqlite3.so library file, but there is no "main" function in which to call vfstrace_register so that the VFS is actually available. Is there some other hook for the library case where I can set this up? If no, how do I make a new VFS available?
SQLite is initialized via the sqlite3_initialize() function, which is called automatically when various functions such as sqlite3_open() are called by the user, although it is a no-op on subsequent invocations. This function in turn calls the OS specific initialization function sqlite3_os_init(). This is the function that initializes all the VFSes that are built into SQLite.
For the example VFS given, append test_vfstrace.c to the amalgamation and then put a call like this in sqlite3_os_init() right before the return statement:
vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1);
Then build the library with these modifications.
The last parameter's value of 1 will make this VFS be the default, so if you don't want trace messages printed for every SQLite operation performed via code linked the library you just created change this to 0 and explicitly specify this VFS when opening a database to trace the calls for. For instance, specify the SQLITE_USE_URI compile time option, and then pass a filename of the form: "file:database.db?vfs=unix" where "database.db" is the actual name of the file to open.

How to incorporate OpenQuery into an SSDT project (without SQL71501/'unresolved reference to object' errors)

I have a Visual Studio SSDT project where one view references a linked server via 4 part naming. I have set up a project for the database on the linked server and created a reference from the main project to the "linked server" project, and all works fine.
I have been instructed to use OpenQuery instead of 4 part naming convention because actually OpenQuery does run 2-3x faster than query via 4 part naming convention.
However, when I change the view in SSDT to use open query, I get an error:
Severity Code Description Project File Line Suppression State
Error SQL71501: View: [schema].[view] has an unresolved reference to object [LINKEDSERVER].
I have tried defining [LINKEDSERVER] in a script in the project:
exec master.dbo.sp_addlinkedserver #server = N'LINKEDSERVER', #srvproduct=N'SQLSERVER', #provider=N'SQLNCLI', #datasrc=N'SERVERNAME'
And also tried adding same into the referenced project.
So, how to incorporate OpenQuery into an SSDT project without incurring SQL71501/'unresolved reference to object' errors?
I’ve been fighting this same issue for a while. I solved by:
Importing the master.dacpac that included the needed Linked servers.
Creating a database reference from the calling database to the DACPAC of the database I'm referencing (insure Suppress Reference Warning is checked).
used the syntax OpenQuery([LINKEDSERVER], ‘xxx’); and not OpenQuery([$([LINKEDSERVER])], ‘xxx’);
I hope this helps!

MyGeneration.dOOdads problem with MySQL connection in ASP.net with stored procedures

I am using MyGeneration.dOOdads which helps in generating Business layer and Data layer easily, but currently I am facing a problem with it.
I had worked with MS SQL database and was successful, but now I have to work with MySQL 5.
I have the generated data layer classes of MySQL database successfully, but when I add them in my project along with the reference of MyGeneration.dOOdads dll file it gives error of no MySql4Entity class in the namespace.
I have generated the class according to the given instructions and also added the reference of mysql.data in the project but still this error is occuring.
Please guide me if you have used MyGeneration.doodads for MYSQL5 database in asp.net.
Also please tell me how to make stored procedure using MyGeneration.doodads of MYSQL database?
open doodads project (source code) .. right click on MySql4Entity class (and other classes related to mysql) and choose 'properties' the choose build action as 'compile' from the list ... to compile the file then build the project and it its output as reference to your project ...

Resources