lsc icon indicating copy to clipboard operation
lsc copied to clipboard

Unchanged numeric value gets always updated

Open pipoprods opened this issue 1 year ago • 6 comments

I'm synchronising a LDAP to a MariaDB. The gosaMailQuota LDAP attribute goes to quota in MariaDB, which is a bigInt:

+----------------+------------+------+-----+---------+-------+
| Field          | Type       | Null | Key | Default | Extra |
+----------------+------------+------+-----+---------+-------+
| quota          | bigint(20) | YES  |     | <null>  |       |
+----------------+------------+------+-----+---------+-------+

On the LSC side, the quota value is generated in a dataset:

<dataset>
        <name>quota</name>
        <policy>FORCE</policy>
        <forceValues>
                <string>srcBean.getDatasetFirstValueById("gosaMailQuota")</string>
        </forceValues>
</dataset>

and extracted from SQL request in SqlMap:

SELECT quota FORM table WHERE [...]

In this first version, the value gets updated even if the LDAP value matches the DB.

I've tried converting the value to a numeric type, behavior is the same:

  • <string>parseInt(srcBean.getDatasetFirstValueById("gosaMailQuota"), 10)</string>
  • <string>new java.math.BigInteger(srcBean.getDatasetFirstValueById("gosaMailQuota"))</string>

To have LSC update the value only when it changes, I had to convert to string in SQL and compare with the value from LDAP:

<dataset>
        <name>quota</name>
        <policy>FORCE</policy>
        <forceValues>
                <string>srcBean.getDatasetFirstValueById("gosaMailQuota")</string>
        </forceValues>
</dataset>

and extracted from SQL request in SqlMap:

SELECT CONCAT('', quota) FORM table WHERE [...]

pipoprods avatar Apr 18 '24 13:04 pipoprods

Your workaround is a good idea.

A test could be to declare gosaMailQuota as binary attribute in LDAP connection. This should prevent LSC to force the value to be casted as String.

coudot avatar May 28 '24 16:05 coudot

Unfortunately, the behavior is still the same with attribute declared as binary:

<ldapConnection>
	<binaryAttributes>
		<string>gosaMailQuota</string>
	</binaryAttributes>
</ldapConnection>

Should I try and change something on the dataset side?

pipoprods avatar May 31 '24 13:05 pipoprods

Yes please try also to use this in your dataset:

<dataset>
        <name>quota</name>
        <policy>FORCE</policy>
        <forceValues>
                <string>srcBean.getDatasetBinaryValuesById("gosaMailQuota")</string>
        </forceValues>
</dataset>

See https://lsc-project.org/javadoc/latest/org/lsc/beans/LscBean.html#getDatasetBinaryValuesById-java.lang.String-

coudot avatar May 31 '24 13:05 coudot

It's completely breaking data insertion as the dataset produces binary data that doesn't match database type:

Error: 1366-22007: Incorrect integer value: '[B@3dc5e5ba' for column `quota` at row 3

pipoprods avatar May 31 '24 14:05 pipoprods

My mistake, try getDatasetFirstBinaryValueById instead of getDatasetBinaryValuesById

I don't have any idea after this...

coudot avatar May 31 '24 14:05 coudot

Insertion is working correctly, but records still get updated at each run. Thanks for the ideas :)

pipoprods avatar May 31 '24 14:05 pipoprods