Add Function Import not available for function - stored-procedures

I've added a function in my database and I wanted it to be callable in my code. For stored procedures I've right clicked on the SP and selected Add Function Import in Model Browser to achieve this, but this option is not available for my function. What can I do to import the function?

Database functions are not available for Function import. Function import works only with stored procedures. You must manually create stub function and mark it with EdmFunction attribute for database function available in your model.

Related

Snowflake Global function and variable

I have a many (snowflake) javascript stored procedures per data pipeline , in all the procedures I have this function defined.
create or replace procedure procedure1()
returns strint
language javascript
as
'
function returnResult(sql_text){
rs = snowflake.execute({sqlText:sql_text});
rs.next();
return rs.getColumnValue(1);
}
--declare constants
--declare variables
--perform some checks
return returnResult(`call procedure2('param1', 'param2')`);
'
;
I use this to execute sql's multiple times inside the same procedure .like
return returnResult(`call procedure2('param1', 'param2')`);
Note: I don't want to use the function call in 'select statement'
Is there a way I store this function 'returnResult' globally once and use in all the stored procedures ?
Along with this, Can I define any variable globally and use in multiple stored procedures (pipelines) ?
I tried creating UDF's but it does not look to be the right approach.
There is currently no way to define helper functions globally for Snowflake JavaScript stored procedures or UDFs. You need to include the helper functions in every stored procedure or UDF that references them.
Since Snowflake Java stored procedures and UDFs can reference compiled JAR files, you can implement a single helper function (or in fact an entire class) and reuse that code across a number of different stored procedures. Python stored procedures and UDFs can also reference compiled pickle files, so they can reference shared functions and libraries too.
It's also possible to have Snowflake compile Java or Python stored procedures and UDFs if you do not want to deal with external IDEs or a framework like Snowpark. That way a main SP or UDF can include a number of functions that other SPs or UDFs reference.

How to avoid writing an import for every single file in dart/flutter?

I am making a flutter application and I created a file/class for each custom widget I am using. Then, I imported all of these files into the main screen but I don't like how it looks. Especially because if I want to add another widget or delete the one I would need to fiddle with the imports.
Is there something like C# namespaces where I can just make one import for all files in folder/namespace?
I already tried using library/part with success but then in https://www.dartlang.org/guides/libraries/create-library-packages says that I should avoid using part/part of. So, are we expected to import each and every file?
Instead of having:
import 'package:custom_widgets/custom_multiplechoice.dart';
import 'package:custom_widgets/custom_singlechoice.dart';
import 'package:custom_widgets/custom_time.dart';
import 'package:custom_widgets/custom_yesnochoice.dart';
import 'package:custom_widgets/custom_date.dart';
I would like to have:
import 'package:custom_widgets';
Yes there is, you can use export to achieve what you want.
You can place all your widgets in a folder, for example libs/src/ and then create file custom_widgets.dart in libs/ and use export like this inside custom_widgets.dart:
export 'src/custom_multiplechoice.dart';
export 'src/custom_singlechoice.dart';
export 'src/custom_time.dart';
export 'src/custom_widgets/src/custom_yesnochoice.dart';
export 'src/custom_date.dart';
Once you import custom_widgets.dart, all those widgets will be available to you.
Check this out, its all explained here: Dart: Organizing a library package
Update:
In Dart there are no namespaces like in most other languages.
Dart uses libraries for encapsulation, data hiding.
Only way to import a class into your code is to use import in the beginning of your file, which should also be a library.
I have an issue with this too. Imagine a situation where you want to import library dynamically. Let's say you would like to implement MVC pattern in your application, if you are doing this on the server, you would have a Router class that would analyze URL and decide what Controller class to instantiate and what Method from that Controller to invoke. Now every URL would trigger different Controller, and you don't know it in advance, its up to your Router to detect a Class to instantiate. What you need to do in this situation is import every Controller that could get instantiated at the beginning of your file. And I have issues with that. What if your application gets big and you have to import lets say 20 Controller classes, just so Router / Dispatcher can invoke one of them, and in reality you will invoke only one Controller, as there is only Controller per URL.
Don't have issues with manual loading of Libraries, if they are going to be used, but for situation like described above, Dart fails as there is no "auto loading" of classes like in for example PHP, where you can use auto loaders that use namespaces to find out about location of your class and instantiate a class in the middle of the code dynamically.
There is this extension for VSCode which can help to create this.
Dart Barrel File Generator

How to call function in sql server with entity framework

No idea how to do this;
The client I work for has a database with functions (not stored procedures!) that have a lot of complex logic that we must use since there is no time to reproduce them in C# code. We use database first.
I honestly don't know where to start! I have added the function with "Update the Model" via the edmx, and I see the function appear in the storage section of the xml configuration.
But now? With stored procedures, EF creates methods in the context class. But apparently not so with functions. I do not know what to do from here. Do I manually add a method for the function in this context class?
Please help!

How code written at global scope is used as the entry point for the program execution?

It is mentioned that we need not to write main function in swift.
Rather in 'AppDelegate.swift' we have the below attribute.
#UIApplicationMain
//Alternative for main function
or we need to import main.swift.
But how does playground works without importing any class or main function?
or how
“Code written at global scope is used as the entry point for the program” in swift?

How use TDataset and Dll with Delphi

I'd like create a dll to import data from a file (different format, for example csv, txt, xls, ...). My idea is this: the dll load the data with her "engine" then send this data to my application so my application can show them inside a grid.
This is my second DLL so I have some problems/questions.
I think my DLL should send the data to a TDataset on my application but how can I call a DLL with a TDataset as argument?
Any suggestions?
What is the easiest way to accomplish what I have in mind? (if possible)
If you are the creator of those DLL's, then consider to use packages instead of DLL. This will avoid the problems, like dublicate Delphi RTTI, plain DLL API. Then you will need to properly split classes between packages, load packages statically or dynamically, get reference to a class implementing import engine, and call the corresponding method with a dataset reference as a parameter value.
Easier way for you would be to store the data directly into database in DLL. And after import you just refresh your TDataset.
BTW, you don't "call DLL", you call some method that is public in DLL and there you can use arguments as in normal methods.
EDIT: For more generic DLLs that don't require data components just send data in struct
TMyData
{ int ID;
String Value;
};
int MyDataImport(TMyData & data)
{
...
}

Resources