B4J Question jrdc2 server: How to log sql string

yfleury

Active Member
Licensed User
Longtime User
I have in config.properties a sql string like
B4X:
sql.select_mytable= select * from table where item1 = ? and item2 = ? order by item3

I want to log the sql string with parameters on jrdc2 server like
B4X:
select * from table where item1 = 33 and item2 = "old" order by item3

Is it possible?
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
I run jrdc 2 server in debug mode I just want to show parameters on log tab
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Note: Untested
You could add the following code to both ExecuteQuery2 and ExecuteBatch2 of the RDCHandler class module of the jRDC2 source code:
B4X:
#If Debug
   Dim sb As StringBuilder
   sb.Initialize
   sb.Append($"Query: ${Main.rdcConnector1.GetCommand(cmd.Name)}"$)
   Dim first As Boolean = True
   For Each parameter As Object In cmd.Parameters
       If first Then
           sb.Append($" Parameter(s): ${parameter}"$)
           first = False
       Else
           sb.Append($", ${parameter}"$)
       End If
   Next
   Log(sb.ToString)
#End If
In ExecuteQuery2, place it after
B4X:
Dim cmd As DBCommand = m.Get("command")
In ExecuteBatch2, place it in the loop that execute the commands, after
B4X:
For Each cmd As DBCommand In commands
 
Upvote 0

yfleury

Active Member
Licensed User
Longtime User
Note: Untested
You could add the following code to both ExecuteQuery2 and ExecuteBatch2 of the RDCHandler class module of the jRDC2 source code:
B4X:
#If Debug
   Dim sb As StringBuilder
   sb.Initialize
   sb.Append($"Query: ${Main.rdcConnector1.GetCommand(cmd.Name)}"$)
   Dim first As Boolean = True
   For Each parameter As Object In cmd.Parameters
       If first Then
           sb.Append($" Parameter(s): ${parameter}"$)
           first = False
       Else
           sb.Append($", ${parameter}"$)
       End If
   Next
   Log(sb.ToString)
#End If
In ExecuteQuery2, place it after
B4X:
Dim cmd As DBCommand = m.Get("command")
In ExecuteBatch2, place it in the loop that execute the commands, after
B4X:
For Each cmd As DBCommand In commands

You are the king Thanks
I test your code and it work well
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Upvote 0
Top