hernad / harbour

agile harbour (a.k.a hernad's fork)
Other
1 stars 3 forks source link

PostgreSQL SQLMIX and NULL values #3

Open hernad opened 4 years ago

hernad commented 4 years ago

Original DBF/CDX tables doesn't handle with null values. So, when I have started to changed data with SQL sources, my application didn't know how to handle those NIL values instead of empty string like it was when the data source was real DBF table.

There were two solutions:

  1. To handle situation on postgresql server-side, or

  2. simply change fetching of string NULL into SQLMIX/sddpg driver.

The third solution to change my application behaviour was excluded (to much work).

It have seemed more robust for me to patch that inconsistency in sddpg.

Here is relevant code:

https://github.com/hernad/harbour/blob/master/src/sddpg/core.c#L584

      case HB_FT_DOUBLE:

          if ( !pValue ) // empty
               hb_itemPutNDLen( pItem, (double) 0.0,
                         ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ),
                         ( int ) pField->uiDec );
           else {

                fDbl = hb_strToNum( (const char *) pValue, &lVal,  &dVal);
                hb_itemPutNDLen( pItem, fDbl ?  dVal : (double) lVal ,
                                            ( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ),
                                            ( int ) pField->uiDec );
            }
            break;
hernad commented 4 years ago

It have seemed more robust for me to patch that inconsistency in sddpg.

To add: If I need handling with NULL values different than empty string in application, I can use TPostgreSQL API