Dynamic SQL in DELETE statement causes Ebase to crash

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Dynamic SQL in DELETE statement causes Ebase to crash

#1

Postby Segi » Wed Sep 28, 2016 6:12 pm

I have a database resource with this DELETE statement:

Code: Select all

DELETE FROM PermissionAssignments &&WHERECLAUSE
When the user checks a checkbox, the change event builds the where clause

Code: Select all

if (tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.PermissionWhereClauseID.value != 1) {
     tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.WHERECLAUSE.value="WHERE UserID=&&ResolutionUserID AND PermissionID=&&ResolutionPermissionID";
} else {
     tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.WHERECLAUSE.value="WHERE UserID=&&ResolutionUserID";
}
I then call tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.deleteRow(); to delete the row and tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.updateTable(); to update the database.

The call to updateTable() causes this error

Code: Select all

Wrapped com.ebasetech.xi.exceptions.FormRuntimeException: unable to set column ResolutionUserID with type INTEGER from table column with type INTEGER, types incompatible? - Invalid parameter index 1. (ADMIN_INVALIDPERMISSIONS_REMOVEPERMS_CHANGE#17)
Why doesn't Ebase let me dynamically build the where clause and why am I getting an error substituting an INTEGER for an INTEGER. This is completely valid SQL and should work
0 x

AJDulk
Ebase User
Posts: 94
Joined: Fri Sep 14, 2007 12:18 pm
Location: The Netherlands
Contact:

Re: Dynamic SQL in DELETE statement causes Ebase to crash

#2

Postby AJDulk » Thu Sep 29, 2016 11:15 am

It would be better to take the where clause out the table, use a standard field instead (instead of tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.WHERECLAUSE.value you would then be using fields.ADMIN_USERS_WITH_INVALID_PERMISSIONS_WHERECLAUSE.value).

What I think is happening is that you are setting the where clause at the row you are going to delete. The moment you delete the row, you delete the where clause. Since the where clause is deleted, you now get an error.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

Re: Dynamic SQL in DELETE statement causes Ebase to crash

#3

Postby t4nu » Sat Oct 01, 2016 8:17 am

Hi,
I usually put that (WHERECLAUSE) as a dynamic, and then map it to a fields. When the time to create the criteria, I just assign that criteria to that field.
So far I always can get what I want.
Segi wrote:I have a database resource with this DELETE statement:

Code: Select all

DELETE FROM PermissionAssignments &&WHERECLAUSE
When the user checks a checkbox, the change event builds the where clause

Code: Select all

if (tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.PermissionWhereClauseID.value != 1) {
     tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.WHERECLAUSE.value="WHERE UserID=&&ResolutionUserID AND PermissionID=&&ResolutionPermissionID";
} else {
     tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.WHERECLAUSE.value="WHERE UserID=&&ResolutionUserID";
}
I then call tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.deleteRow(); to delete the row and tables.ADMIN_USERS_WITH_INVALID_PERMISSIONS.updateTable(); to update the database.

The call to updateTable() causes this error

Code: Select all

Wrapped com.ebasetech.xi.exceptions.FormRuntimeException: unable to set column ResolutionUserID with type INTEGER from table column with type INTEGER, types incompatible? - Invalid parameter index 1. (ADMIN_INVALIDPERMISSIONS_REMOVEPERMS_CHANGE#17)
Why doesn't Ebase let me dynamically build the where clause and why am I getting an error substituting an INTEGER for an INTEGER. This is completely valid SQL and should work
0 x


Who is online

Users browsing this forum: No registered users and 45 guests