evseevnn-zz / php-cassandra-binary

PHP library for Cassandra database via a binary protocol.
http://evseevnn.github.io/php-cassandra-binary/
MIT License
69 stars 33 forks source link

0 - value integers(or numbers) read as null issue resolved #45

Open andreizet opened 10 years ago

andreizet commented 10 years ago

If in an int column (for example) a null value was inserted, that value was read as null which was not correct. If there were more columns after that one, everything was read as null, even if values were actually there. This issue happened for all types of numbers.

Follow this example to reproduce this issue: ------START------ ------Create this table: ------ CREATE TABLE null_table_example( id int, col_str text, col_int1 int, col_int 2 bigint, PRIMARY KEY (col_str) ); ------Run this insert: ------ insert into null_table_example (id, col_str, col_int1, col_int2) values (1, 'test1', null, 19); ------Run this query from php: ------ select * from null_table_example where col_str = 'test1'; ------END------

It will return good values for "id" and "col_str" but "col_int1" and "col_int2" will be null even if there are numbers; Executing this query from DataStax or DBeaver will return the correct values (0 for "col_int1" and 19 for "col_int2");

I've added a method that returns a sake value for null items depending of the data type. Also, when a null was read, the size of it's byte value was -1, thing that leaded into putting all the rest of the columns after the null one into that one until it was converter from bytes and it becomed null, see my commit of DataStream.php;

Thanks!

steambao commented 10 years ago

Can't wait for this fix! Tested and fixes all my 'unpack(): Type l: not enough input' when selecting nulls.

evseevnn-zz commented 10 years ago

I will do this tonight