B4J Question jRDC2 - "Include"

LucaMs

Expert
Licensed User
Longtime User
I must confess that I haven't looked on the site, as currently I'm just curious, I don't have a VPS or similar.

In the tutorial about jRDC2 it is said that it is an excellent alternative to PHP and I agree; but is it mandatory to write all queries in the config.properties file? A feature similar to PHP's Include would be very useful. Being a middle-server developed by Erel and being he brilliant (genius!), he could also invent something equally effective, such as being able to embed libraries instead of text (I don't know, right now I need at least two more coffees to wake up ?).
 

LucaMs

Expert
Licensed User
Longtime User
jRDC2 like many other projects shared in this forum is written in B4X so you can modify it. Simple as that. If you put any files in Files tab then it become asset files inside the jar which is readonly. If you put any files to Objects folder then it will not be readonly.
Yes, you are probably referring to the test I attached, in which I put the .rdc text files in the Object folder - wrong place, but it wasn't important, the crime series was more important ?
I'm rather ashamed of this long thread I wrote before seeing that jRDC2 is available as source code! :(:(:(
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
jRDC2 like many other projects shared in this forum is written in B4X so you can modify it. Simple as that. If you put any files in Files tab then it become asset files inside the jar which is readonly. If you put any files to Objects folder then it will not be readonly.
I think that put something in objects file is good for debug, for fast checking your app..

Start position of assets must always at files... and from there making first a check if file exists at the target directory (dirapp, dirdata) - and if not copy (first time) where we want...

Then user must know where is this file (dirapp, dirdata) to have the option to edit...
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Yes, you are probably referring to the test I attached, in which I put the .rdc text files in the Object folder - wrong place, but it wasn't important, the crime series was more important ?
I'm rather ashamed of this long thread I wrote before seeing that jRDC2 is available as source code! :(:(:(
It is time to take a look at who is this beauty.

To summarize, it is not a compiled library but a product that make use of B4J Server and other libraries.

It can be use out of the box or extended for example to support connection to more than one database.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This is the eleventh year that I have been a member of B4X, so I know a little about the Object folder :) .

The big mistake I made was not seeing that jRDC2 is a project, not a compiled library/SW. The reason is mainly that I was just curious, because I had just read a question about jRDC2, which is certainly useful but which I could currently only use on my PC, on LAN.

All this does not exclude that adding the PHP-style #Include functionality to it is useful. Since jRDC2 is source code, you can do it yourself, of course, but it is a product of Erel and if I were him I would do it, for the benefit of all members.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Start position of assets must always at files... and from there making first a check if file exists at the target directory (dirapp, dirdata) - and if not copy (first time) where we want...
If you check the Web Server example, www folder is kept inside Objects folder. Objects folder is the File.DirApp.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
If you check the Web Server example, www folder is kept inside Objects folder. Objects folder is the File.DirApp.
yes i know :)... but is wrong to put files at objects for real project use... because will never be copied at stand alone executable creation...

Actually DirApp is objects at debug/release when running from B4J...

when running from jar or exe.... goes into bin for dirapp :)
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
This is the eleventh year that I have been a member of B4X, so I know a little about the Object folder :) .

The big mistake I made was not seeing that jRDC2 is a project, not a compiled library/SW. The reason is mainly that I was just curious, because I had just read a question about jRDC2, which is certainly useful but which I could currently only use on my PC, on LAN.

All this does not exclude that adding the PHP-style #Include functionality to it is useful. Since jRDC2 is source code, you can do it yourself, of course, but it is a product of Erel and if I were him I would do it, for the benefit of all members.
you can test it on your lan... :)

actually it is easier to test on your lan from testing through internet (need more setup)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I think in general "include" is nice idea... will be better to read code and compile at runtime... but only in my dreams...
Please note that the #include that @LucaMs is referring to pertains to the config.properties file that, among other things, contains the SQL queries that can be used by clients connecting to the jRDC2 server, but no B4X code.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Please note that the #include that @LucaMs is referring to pertains to the config.properties file that, among other things, contains the SQL queries that can be used by clients connecting to the jRDC2 server, but no B4X code.
I know... but this is my secret desire

ps: also the reason I am that i mention it... is because mentioned PHP Include... PHP is a scripting language and with include... you can have also code :)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
you can test it on your lan... :)

actually it is easier to test on your lan from testing through internet (need more setup)
Yes, I did it for one of my websocket servers. I even asked my provider to assign me a fixed IP (and I got it) because I was a bit tired of using one of those services, like duckdns.

But, I repeat, in this case it was just curiosity, due to a question I read yesterday.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Just because I was bored...

I modified LoadSQLCommands (RDCConnector class):
B4X:
Private Sub LoadSQLCommands(config As Map)
    Dim newCommands As Map
    newCommands.Initialize
   
    Dim CmdsFileName As String
   
    For Each k As String In config.Keys
        If k.StartsWith("sql.") Then
            newCommands.Put(k, config.Get(k))
        Else
            If k.ToLowerCase.StartsWith("include") Then
                CmdsFileName = config.Get(k)
                ReadAndAddExtCmds(CmdsFileName, newCommands)
            End If
        End If
    Next
    commands = newCommands
End Sub

and added a Sub:
B4X:
Private Sub ReadAndAddExtCmds(FileName As String, mapCommands As Map)
    Dim ExtCmdsStr As String
    ExtCmdsStr = File.ReadString(File.DirAssets, FileName)
    Dim Cmds() As String
    Cmds = Regex.Split(CRLF, ExtCmdsStr)
    Dim Key, Value As String
    For Each Cmd As String In Cmds
        Key = Regex.Split("=", Cmd)(0)
        Value = Regex.Split("=", Cmd)(1)
        mapCommands.Put(Key.Trim, Value)
    Next
End Sub

I added this line to config.properties:
B4X:
include1=Animals.rdc
and a text file, Animals.rdc, to the Files folder, the content of which is:
B4X:
sql.insert_animal=INSERT INTO animals VALUES (null, ?,?)
sql.select_animal=SELECT name, image, id FROM animals WHERE id = ?;

It should work; I ran the server in debug mode and followed the flow step-by-step, but I didn't develop a client (I'm bored but also lazy ?)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I suggest you check my jRDC2 template for server and client (B4X).

It can be run out of the box with auto generated database. Just edit the server IP in client app and it is ready to go.

 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I suggest you check my jRDC2 template for server and client (B4X).

It can be run out of the box with auto generated database. Just edit the server IP in client app and it is ready to go.

I'll try, thank you.

Surely you understood that my previous post was still related to "Include"; that may be a solution, it should work.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I actually modified jRDC2 so it gets its queries from a special table in the server DB it connects to. In that table I include a record with the version. This is loaded into JRDC as well. When I update the table I up the version. In my apps I store that version and update it as well. jRDC2 was modified so with a special Sub called CheckVersion that compares the version it has to the one passed by the app. If the app version is NEWER then jRDC2 RELOADS the queries from the server table (Including the Version) and checks again. If the version is still old then the app pops up a warning they need to contact us for an update. IF the version matches or is > than the app then they are good to go.

This way the server never needs to be restarted to get updates.

Here is a sample of the table:
Ra_Type    Ra_CmdName    Ra_Command    Ra_Comments    Ra_CS
SQL    CheckIfJobOnMachine     SELECT Tk_JobNum, Tk_TimeIn, FORMAT(Tk_TimeIn,'hh:mm') TimeInOnly, ID, CONVERT(NVARCHAR(10), Tk_Date, 1) Tk_Date, Tk_Emp_Num, datediff(minute, [Tk_TimeIn], GETDATE()) Minutes FROM TimeClock  WHERE Tk_Machine = ? AND Tk_JobNum = ? AND Tk_SeqNum = ? AND Tk_TimeOut Is Null AND Tk_TimeIn IS NOT Null;    Created For Opmanage DC 3/14/23    0
SQL    DB_NAME    SELECT DB_NAME () DBNAME    5/30/21 - Kim    0
DBVersion    DBVersion    1.224    this This version number is loaded by server when it starts.  If it does NOT match DBVersion on the APP    0
SQL    EmpRateQry    SELECT Emp_Rate FROM Employees WHERE Emp_Num = ?;    Original 1/16/21    0

We have frequent updates that involve SQL server updates so we have arrangements with our customers to install those updates. That means updating the SQL data is relatively easy. Getting access and or explaining the process of updating an .ini file on THEIR server would be ore difficult and time consuming.

Because many of our customers devices are not connected to the internet I also store the APP versions for B4A/i/J. The app checks its version against the one stored on the server and let's the user know if they need to update their device.

I thought I posted my jRDC2 years ago but I can't find it. It there is any interest let me know and I will post it and the supporting table schemas and queries and some B4A code that supports it.
 
Upvote 0
Top