CodeName One, SQLite and JSON1 Extension - json

I've written a CodeName One application in NetBeans and I'm testing via the Simulator.
I have a local SQLite database and can execute a simple query in my application e.g.
SELECT *
FROM tempJSON;
When I try to introduce a function (e.g. json_tree) from the JSON1 Extension (https://www.sqlite.org/json1.html) e.g.
SELECT j.value
FROM tempJSON AS d
JOIN json_tree(d.textJSON) AS j
WHERE j.key = 'RunnerName';
I receive the following error.:
java.io.IOException: [SQLITE_ERROR] SQL error or missing database (near "(": syntax error)
Note: both queries execute successfully in SQLiteStudio
What am I missing? (e.g. a configuration issue)
Or is this not possible (yet)?

You can't use extensions in the standard SQLite. On the device we use the builtin sqlite versions and they differ a bit between iOS/Android so relying on an extension that might not be there is problematic.
As a solution we did this: https://www.codenameone.com/blog/spatial-pluggable-sqlite.html
This was done for spatial extensions but the concept is identical if you want to support JSON extensions: bundle your own copy of sqlite.

Related

Connecting Atoti to Oracle database

I want to make a connection to an Oracle database and I have found the following method in the docs:
https://docs.atoti.io/latest/lib/atoti.store.html?highlight=jdbc#atoti.store.Store.load_sql
I call this method with something like this: my_store.load_sql(url, query, username=my_username, password=my_password)
And I use a URL with this form: 'jdbc:XX.XX.XX.XX:YYYY/ZZZZ', but I get the following error:
ValueError: No driver provided and cannot infer it from URL.
I also created this config with a path to a jdbc jar file in my SQL Developer folder, but the error persists:
my_jdbc = 'ojdbc8.jar'
tt.config.create_config(extra_jars = my_jdbc)
Does anyone know how I can solve it or have any example of loading stores from an Oracle database?
Thanks in advance.
The atoti-sql plugin comes with the Oracle driver so you don't need to add an extra jar to the config. However you do need to pass the driver when calling my_store.load_sql. These can be found in the atoti_sql.drivers module.
In your case since you are using an Oracle database, the correct code should be something like:
my_store.load_sql(
url,
query,
username=username,
password=mypassword,
driver=atoti_sql.drivers.ORACLE
)

JSON FX results not working for Xcode

I have an application that has extensively used server calls and i used jsonfx to parse the results and when i build the project from unity and run it on my mac it says
(Filename: currently not available on il2cpp Line: -1)
and application does not processed which is expected because my application depends extensively on responses from the api it hits.
Everything works swiftly on android.
i found out that Jsonfx is not compatible on ios platform an alternative for that is Newtonsoft.Json
simply put use this :
<T>Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonString)
instead of JsonFx.Json.Reader
JsonFx.Json.JsonReader reader = new JsonFx.Json.JsonReader ();
<T>reader.Read<T> (jsonString);
offcourse you will nedd to add the following files to your code
NewtonsoftJson

How to use TFDJSONDataSets or similar in XE4?

Explanation
Today i have spotted the Delphi XE6 Sample called FireDACJSONReflect and i would to use the way it does the communication between the datasnap server and the client, i want to do it on Mine application using TFDMemTableand TFDJSONDataSets(not really needed, but if there is another way using another components i would like to see it).
** Mine application is a delphi-xe4 server and a delphi-xe6 client **
Problem
By the way, my application does use Delphi XE4 instead of Delphi XE6 and want to know what to do to communicate between the datasnap server and the client the same way that FireDACJSONReflect does but i see that i cant have TFDJSONDataSets on my project uses list.
Can i use TFDJSONDataSets on Delphi XE4?
Can i use TFDMemTable without using TFDJSONDataSets to populate it with data?
Some code
I have that lines of code running ok on delphi xe6 and i want to do the same in xe4:
function TDSSMetodoFinanceiro.getCotacaoLista : TFDJSONDataSets;
var
FDQCotacaoLista : TADQuery;
begin
Result := TFDJSONDataSets.create;
TFDJSONDataSetsWriter.listAdd(result, FDQCotacaoLista);
end;
And the question: Why i want to result a TFDJSONDataSet?
Its because i have a TFDMemTable on my delphi xe6 client application that i want to .appendData and it needs a TFDJSONDataset to do it(maybe another way to append data do it is useful).
Any help?
TFDJSONDatasets is, I believe, introduced in XE6, so you cannot use this in earlier versions like XE4. However, I think the job can be done with a FDMemtable instead.
Check out this tutorial, it was written for XE5 but I think this must work in XE4 too.
It starts of from some other example using a Clientdataset, but is then reworked to use a Firedac Memory table.
I should say, give it a try and see if it works out for you.

Jenkins/Hudson job parameters at runtime?

PROBLEM
Let's say I have a jenkins/hudson job (for example free-style) that takes two parameters PARAM_ONE and PARAM_TWO. Now, I do not know the values of those parameters, but I can run some script (perl/shell) to find values of those parameters and then I want the user to select from a dropdown list after which I can start the build.
Is there any way of doing that?
Sounds like you've found a plug-in that does what you need, that is pretty similar to the built-in Parameterized Builds functionality.
To answer your second question: when you define parameterized builds, the parameters are typically passed to your job as environment variables. So you'd access them however you access environment variables in your language, for instance, if you defined a parameter PARAM_ONE, you'd access it as:
In bash:
$PARAM_ONE
In Windows batch:
%PARAM_ONE%
In Python:
import os
os.getenv('PARAM_ONE')
etc.
I imagine this would be the same for the Extended Choice Parameter plugin you are using.
Just install this, and give the parameter in the build script like:
Windows
"your build script" %PARAMONE% %PARAMTWO%
In Java, you can access these parameters off the run object
EnvVars envVars = new EnvVars();
envVars = run.getEnvironment(listener);
for (String envName2 : envVars.keySet()) {
listener.getLogger().println(envName2 + " = " + envVars.get(envName2));
}

MEF: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions for more information"

Scenario: I am using Managed Extensibility Framework to load plugins (exports) at runtime based on an interface contract defined in a separate dll. In my Visual Studio solution, I have 3 different projects: The host application, a class library (defining the interface - "IPlugin") and another class library implementing the interface (the export - "MyPlugin.dll").
The host looks for exports in its own root directory, so during testing, I build the whole solution and copy Plugin.dll from the Plugin class library bin/release folder to the host's debug directory so that the host's DirectoryCatalog will find it and be able to add it to the CompositionContainer. Plugin.dll is not automatically copied after each rebuild, so I do that manually each time I've made changes to the contract/implementation.
However, a couple of times I've run the host application without having copied (an updated) Plugin.dll first, and it has thrown an exception during composition:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions for more information
This is of course due to the fact that the Plugin.dll it's trying to import from implements a different version of IPlugin, where the property/method signatures don't match. Although it's easy to avoid this in a controlled and monitored environment, by simply avoiding (duh) obsolete IPlugin implementations in the plugin folder, I cannot rely on such assumptions in the production environment, where legacy plugins could be encountered.
The problem is that this exception effectively botches the whole Compose action and no exports are imported. I would have preferred that the mismatching IPlugin implementations are simply ignored, so that other exports in the catalog(s), implementing the correct version of IPlugin, are still imported.
Is there a way to accomplish this? I'm thinking either of several potential options:
There is a flag to set on the CompositionContainer ("ignore failing imports") prior to or when calling Compose
There is a similar flag to specify on the <ImportMany()> attribute
There is a way to "hook" on to the iteration process underlying Compose(), and be able to deal with each (failed) import individually
Using strong name signing to somehow only look for imports implementing the current version of IPlugin
Ideas?
I have also run into a similar problem.
If you are sure that you want to ignore such "bad" assemblies, then the solution is to call AssemblyCatalog.Parts.ToArray() right after creating each assembly catalog. This will trigger the ReflectionTypeLoadException which you mention. You then have a chance to catch the exception and ignore the bad assembly.
When you have created AssemblyCatalog objects for all the "good" assemblies, you can aggregate them in an AggregateCatalog and pass that to the CompositionContainer constructor.
This issue can be caused by several factors (any exceptions on the loaded assemblies), like the exception says, look at the ExceptionLoader to (hopefully) get some idea
Another problem/solution that I found, is when using DirectoryCatalog, if you don't specify the second parameter "searchPattern", MEF will load ALL the dlls in that folder (including third party), and start looking for export types, that can also cause this issue, a solution is to have a convention name on all the assemblies that export types, and specify that in the DirectoryCatalog constructor, I use *_Plugin.dll, that way MEF will only load assemblies that contain exported types
In my case MEF was loading a NHibernate dll and throwing some assembly version error on the LoaderException (this error can happen with any of the dlls in the directory), this approach solved the problem
Here is an example of above mentioned methods:
var di = new DirectoryInfo(Server.MapPath("../../bin/"));
if (!di.Exists) throw new Exception("Folder not exists: " + di.FullName);
var dlls = di.GetFileSystemInfos("*.dll");
AggregateCatalog agc = new AggregateCatalog();
foreach (var fi in dlls)
{
try
{
var ac = new AssemblyCatalog(Assembly.LoadFile(fi.FullName));
var parts = ac.Parts.ToArray(); // throws ReflectionTypeLoadException
agc.Catalogs.Add(ac);
}
catch (ReflectionTypeLoadException ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
}
CompositionContainer cc = new CompositionContainer(agc);
_providers = cc.GetExports<IDataExchangeProvider>();