I need to enumerate all parameters in a MemSQL function. Is there an easier way other than using SHOW CREATE FUNCTION and then parsing the definition? For example, when using MySql, I could use
connection.GetSchema("Procedure Parameters",
new string[] { null, database, structureName });
Unfortunately there isn't really a better approach right now. The GetSchema method from your example makes use of a MySQL metadata table that is currently unsupported in MemSQL.
Related
Sorry for the naive question, but I got stuck while following all the pieces of tutorials available.
So, is there a way to populate a Database db from a simple List rather than loading it reading a file?
Basically what I'm looking for is something similar to:
List objects = ...
Database db = ClassGenericsUtil.parameterizeOrAbort(ArrayDatabase.class, params, objects);
db.initialize();
Thanks in advance.
What are the contents of your Strings?
Same as understood by the ELKI parsers?
This will likely require some code modifications, because the parsers are designed around Javas InputStream. I don't suggest wrapping a List<String> into an InputStream although that would probably be the least-effort approach.
Why don't you try extending AbstractDatabaseConnection (or implementing DatabaseConnection)? The database connection format, MultipleObjectsBundle is not much more than List<Object> and relation metadata; fairly easy to construct.
Alternatively, you could use your own code to parse the Strings into double[] and then use ArrayAdapterDatabaseConnection; which will wrap the double[] as DoubleVector for you and construct the bundles.
I have created a function function_1() in Postgres.
Now I want to create another similar function function_2() and copy the content of function_1().
Any Postgres command line can do that?
So far I only used copy&paste method in the command line to create function_2() (need to change the function name to "function_2" after paste)
If you are using the GUI pgAdmin, you can simply select the function in the object browser and open the reverse engineered SQL script in an SQL editor window.
There is a dedicated item in the options to automate it:
Options - Query tool - Query Editor - Copy SQL from main window to query tool
pg_dump the function definition, or use the pg_get_functiondef function to get the function definition. Modifying it is up to you.
If you're trying to programmatically create functions you might be better off with PL/PgSQL's EXECUTE command and the format function to create dynamic functions.
It's pretty unusual to need to do this, suggesting you're probably doing something that's much more easily done another way.
I've got a store procedure call returning a recordset whith field unknown in advance. For some interop reason I need to make it working on 3.5, so I don't have any dynamic support.
Is there some built-in solution in dapper? I did not find any by myself.
If there is no such a solution, does it make sense ( and does it work ) to create on the fly a type exposing the property I would fetch ?
EDIT
I managed to add a completely external solution ( without tweaking the original codebase ) by creating a dynamic object in c# 3.0.
Here is the extension dapper code
and here the factory for the dynamic object.
Well, actually the dynamic support in dapper is implemented via ExpandoObject, which is basically just a dictionary. It would be pretty simple to tweak the existing code to return IDictionary<string,object> instead of dynamic in the case of 3.5
Up front, the guy on the keyboard here is way overdue on the sleep department. But also kinda desperate.
I have a Data-service [WebGet] method, setup like this.
[WebGet]
public string Finalize(string PayloadObject, string CltUUID, string Comment){..}
It return a simple string, depending on the outcome of the execution inside. This is working fine.
I call it like this
var res = base.ServiceRef.CreateQuery<DBcontext>("Finalize")
.AddQueryOption("PayloadObject", string.Format("'{0}'", builder.ToString()))
...
How do I get this query to materialize?
Usually one uses res.ToList(), ToArray() or .First(). If I do, I get an exception. Using .ToString() does not execute the query, just returns the url.
The query works, if I break in a line after this code and click 'View...' in the debugger, the query is executed, the method runs on the server.
It seems I just don't get it to run, what am I missing?? besides sleep
Thanks for any pointers
Regards, Andreas
I think you cannot use CreateQuery to call operation returning single value. You must use Execute instead. MSDN documentation also mentions that operations returning primitive types cannot use QueryOption which make sense because query option is used to define query for IQueryable. If you need to pass parameters try to use common WCF REST approach to specify template in WebGet and on client side use the URI with parameters correctly included.
You can also try to use SingleResultAttribute on your service operation.
I am implementing a plugin system with Lua scripts for an application. Basically it will allow the users to extend the functionality by defining one or more functions in Lua. The plugin function will be called in response to an application event.
Are there some good open source plugin frameworks in Lua that can serve as a model?
In particular I wonder what is the best way to pass parameters to the plugin and receive the returned values, in a way that is both flexible and easy to use for the plugin writers.
Just to clarify, I am interested in the design of the API from the point of view of the script programming in Lua, not from the point of view of the hosting application.
Any other advice or best practices related to the design of a plugin system in Lua will be appreciated.
Lua's first-class functions make this kind of thing so simple that I think you won't find much in the way of frameworks. Remember that Lua's mantra is to provide minimal mechanism and let individual programmers work out policy for themselves.
Your question is very general, but here's what I recommend for your API:
A single plugin should be represented by a single Lua table (just as a Lua module is represented by a single table).
The fields of the table should contain operations or callbacks of the table.
Shared state should not be stored in the table; it should be stored in local variables of the code that creates the table, e.g.,
local initialized = false
return {
init = function(self, t) ... ; initialized = true end,
something_else = function (self, t)
if not initialized then error(...) end
...
end,
...
}
You'll also see that I recommend all plugin operations use the same interface:
The first argument to the plugin is the table itself
The only other argument is a table containing all other information needed by the operation.
Finally, each operation should return a result table.
The reason for passing and returning a single table instead of positional results is that it will help you keep code compatible as interfaces evolve.
In summary, use tables and first-class functions aggressively, and protect your plugin's private state.
The plugin function will be called in response to an application event.
That suggests the observer pattern. For example, if your app has two events, 'foo' and 'bar', you could write something like:
HostApp.listeners = {
foo = {},
bar = {},
}
function HostApp:addListener(event, listener)
table.insert(self.listeners[event], listener)
end
function HostApp:notifyListeners(event, ...)
for _,listener in pairs(self.listeners[event]) do
listener(...)
end
end
Then when the foo event happens:
self:notifyListeners('foo', 'apple', 'donut')
A client (e.g. a plugin) interested in the foo event would just register a listener for it:
HostApp:addListener('foo', function(...)
print('foo happened!', ...)
end)
Extend to suit your needs.
In particular I wonder what is the best way to pass parameters to the plugin and receive the returned values
The plugin just supples you a function to call. You can pass any parameters you want to it, and process it's return values however you wish.