vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Negative numeric values are not simple queries are not properly decoded

Open arrowwood49 opened this issue 8 years ago • 6 comments

Querying integer column with negative value not working properly.

pg-client Row contains -29 when executing select on column with value -1.

arrowwood49 avatar Nov 07 '18 17:11 arrowwood49

Hi, we need a reproducer in order to investigate

EmadAlblueshi avatar Nov 07 '18 21:11 EmadAlblueshi

Here is the unit test that reproduces the issue with version 0.10.7:

diff --git a/src/test/java/io/reactiverse/pgclient/RxTest.java b/src/test/java/io/reactiverse/pgclient/RxTest.java
index a9ce592..dcb5a5d 100644
--- a/src/test/java/io/reactiverse/pgclient/RxTest.java
+++ b/src/test/java/io/reactiverse/pgclient/RxTest.java
@@ -122,4 +122,20 @@ public class RxTest extends PgTestBase {
       }, ctx::fail);
     });
   }
+
+  @Test
+  public void testNegativeIntegerBug(TestContext ctx) {
+    Async async = ctx.async();
+    pool.rxQuery("INSERT INTO Fortune (id, message) VALUES (-1, 'Yes')")
+        .flatMap(s -> pool.rxQuery("SELECT * FROM Fortune WHERE id=-1"))
+        .subscribe(result -> {
+          ctx.assertEquals(1, result.size());
+          Integer idFromDb = result.iterator().next().getInteger(0);
+          System.out.println("id from DB (expected -1)=" + idFromDb);
+          ctx.assertEquals(-29, idFromDb);    //succeeds
+          ctx.assertEquals(-1, idFromDb);      //fails here
+          async.complete();
+        }, err -> ctx.fail());
+
+  }
 }

The above unit-test fails since expected id value is -1 but SELECT from DB returns -29

Running io.reactiverse.pgclient.RxTest
id from DB (expected -1)=-29
io.reactivex.exceptions.UndeliverableException: java.lang.AssertionError: Not equals : -1 != -29
	at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:366)
...
Caused by: java.lang.AssertionError: Not equals : -1 != -29
	at io.vertx.ext.unit.impl.TestContextImpl.reportAssertionError(TestContextImpl.java:467)
	at io.vertx.ext.unit.impl.TestContextImpl.assertEquals(TestContextImpl.java:363)
	at io.vertx.ext.unit.impl.TestContextImpl.assertEquals(TestContextImpl.java:350)
	at io.reactiverse.pgclient.RxTest.lambda$testNegativeIntegerBug$6(RxTest.java:136)
	at io.reactivex.internal.observers.ConsumerSingleObserver.onSuccess(ConsumerSingleObserver.java:63)
	... 37 more

arrowwood49 avatar Nov 12 '18 04:11 arrowwood49

can you make a PR that adds this test ?

vietj avatar Nov 12 '18 07:11 vietj

can you make a PR that adds this test ?

@vietj Here is the PR https://github.com/reactiverse/reactive-pg-client/pull/204

arrowwood49 avatar Nov 12 '18 16:11 arrowwood49

thanks

vietj avatar Nov 12 '18 16:11 vietj

it has been fixed in the master branch, perhaps you can check with a snapshot ?

vietj avatar Nov 17 '18 14:11 vietj