Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Questions concering SQL Service
Questions concering SQL Service [message #1268439] Mon, 10 March 2014 14:00 Go to next message
daniele fochetti is currently offline daniele fochettiFriend
Messages: 22
Registered: August 2013
Junior Member
Scenario:
Column myCol of table MY_TABLE is nullable.
Value of myCol of row with primaryKey = 1 is null.

Code snippet:

    StringHolder myHolder = new StringHolder();

    SQL.selectInto(
        "SELECT myCol" +
        "FROM MY_TABLE " +
        "WHERE primaryKey = 1 " +
        "INTO :myColHolder"
        , new NVPair("myColHolder", myHolder);


Question:
Is this needed?
if (myHolder != null) {....};


At first glance it might not be, because of
    StringHolder myHolder = new StringHolder();


General Question, could parameters being passed to NVPair be set to null?
How do I verify if a column value is empty string or null?
What is the use of the NVPair constructor
  public NVPair(String name, Object value, Class nullType) {
    m_name = name;
    m_value = value;
    m_nullType = nullType;
  }


and the method
getNullType()


TIA
Daniele
Re: Questions concering SQL Service [message #1268524 is a reply to message #1268439] Mon, 10 March 2014 16:16 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
This is a quick answer, I did not verify it

If the value returned by your database is NULL (the database null), your holder instance will not be null (as you assumed).

I think, the value will be null (the java null):
myHolder.getValue()



For your question about NULL versus empty String, I think you should try it. It might also depend on the Database engine. What are you using? MySQL?



I can remember of one usecase where the nullType parameter is usefull: when you pass a value to the SQL engine directly (as input parameter).
//with myDate beeing a java.util.Date

SQL.selectInto(
        "INSERT INTO myTable (myCol) " +
        "VALUES (:myColHolder) "
        , new NVPair("myColHolder", myDate);


If myDate can be null, the NVPair cannot find out the type of myDate when it is null. This is because the type of null in Java is not known.("x instanceof SomeClass" is false if x is null)

In this case you will need something like:
new NVPair("myColHolder", myDate, Date.class);



If you need more information, feel free to tell. I could look deeper into it.
Re: Questions concering SQL Service [message #1269023 is a reply to message #1268524] Tue, 11 March 2014 09:34 Go to previous message
daniele fochetti is currently offline daniele fochettiFriend
Messages: 22
Registered: August 2013
Junior Member
Hi Jeremie

Many thanks for your super fast answer.

Daniele
Previous Topic:Unique field Id (Class Id) with aditional attributes for RCP Jubula Tests
Next Topic:Sort and preselect in SmartFields
Goto Forum:
  


Current Time: Fri Nov 22 17:45:38 GMT 2019

Powered by FUDForum. Page generated in 0.02062 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top