Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Handling NULL values in PowerBuilder

When it comes to NULL values, PowerBuilder treats them a little different than other languages. Not only that, when null is added, compared to or concatenated with any variable the entire result will become null, but also when given a null parameter most PowerBuilder functions will simply return NULL and perform no action.

To avoid generating possible errors, the solution is to check for the null values and proceed accordingly.
A common example of such case is passing a null text value to the MessageBox function. The function will do simply nothing and the flow will continue with the next line of code.
So instead of:

    MessageBox("", ls_text);

one can wrapp the function like this:

    f_MessageBox(as_text)
    if (IsNull(as_text)) then
        MessageBox("", "null value received!");
    else
        MessageBox("", as_text);
    end if

On the other hand, in PowerBuilder unassigned variables/columns can take different values depending on their source. Table below shows how an unassigned PowerScript variable will be initialized:

string EmptyString (zero length string)
number zero
date 01/01/1900

When external stored procedures or functions need to be called with explicit null value parameters or for any other particular reason when a null value is needed for a variable leaving the value unassigned will generate wrong unexpected results. To proper specify a NULL value, use the SetNull function.

    int ln_location_id = 1; string ls_location_name;
    SetNull(ls_location_name);
    prepare sqlsa from "INSERT INTO locations values (?,?)";
    execute sqlsa using :ln_location_id, :ls_location_name;

Most SQL databases (eg PostgreSQL) do not use null in arithmetic comparisons.
For example following queries will return 0 records.

    SELECT * FROM locations WHERE "name" = null
    SELECT * FROM locations WHERE "name" IN (null)

To get the desired result must use:

    SELECT * FROM locations WHERE "name" IS NULL

A common situation here is where null parameters are supplied to a stored procedure and the results are not what should expect. In this case must evaluate such variables and use a dynamic cursor to provide specific parameters to the function:

    string ls_query_where_clause, ls_query;
    DECLARE crs_stock DYNAMIC CURSOR FOR SQLSA;
    ls_query_where_clause = " WHERE article_id = '" + string(ll_article_id) + "'";
    if (isnull(ll_location_id)) then
        ls_query_where_clause += " AND location_id ISNULL";
    else
        ls_query_where_clause += " AND location_id = '" + string(ll_location_id) + "'";
    end if
    ls_query = "SELECT quantity, cost FROM inv_stock" + ls_query_where_clause;
    PREPARE SQLSA FROM :ls_query;
    sqlca.checksql(true, "");
    OPEN DYNAMIC crs_stock;
    sqlca.checksql(true, "");
    FETCH crs_stock INTO :ldbl_qty, :ldbl_cost;
    // read lines
    CLOSE crs_stock;
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Get Shareaholic
Tags: cursors null nullable PGSql powerbuilder PowerScript

 Posted in: Power Builder
February 2, 2010 | Daniel Bozdoc | 2 Comments

2 Responses

  • Student Loan Refinance
    June 17, 2010
    1

    I’ll come back again to find out your upcoming post! Excellent job done!

  • Free WP Themes
    September 22, 2010
    2

    Good post and this enter helped me alot in my college assignement. Say thank you you for your information.

Leave a Reply

 


  • « Previous post
  • Next post »
  • Recent Posts

    • Installing PyGraphviz on Windows
    • Convert python object to XML representation
    • Liferay Portlet Development
    • Norway Road Show 2011 private meeting invitation
    • Oracle OpenWorld 2011
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Rajkumar Pomaji on Bluetooth PC Remote Control
    • Stelian Morariu on GWT 2.1 – Uploading a file using the RPC mechanism
    • Sergio on GWT 2.1 – Uploading a file using the RPC mechanism
    • Artem on Liferay: Deployment will start in a few seconds… and how to realy start
    • rkd80 on GWT 2.1 – Uploading a file using the RPC mechanism
  • Archives

    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (15)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (83)
      • Microsoft.NET (22)
      • Java (40)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (1)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (1)
    • Web Development (28)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (5)
      • Javascrip/AJAX (8)
      • PHP (7)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2010 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo