null

How to ensure that a field will never be null in a Java class

I am looking for a clean and safe way to ensure tha a field of a class will never be set to null. I would like the field value to be set once in the class constructor and never modified later. I think that he readonly keyword in C# allows this. Is there a way to do the same in Java? class foo { private Object bar; public foo(Objec...

Nullable enums(??) and LinqToSQL

I have the following statement: select new Action { ParentContentType = action.ParentContentType != null ? (ContentType)Enum.ToObject(typeof(ContentType), action.ParentContentType) : null }; ParentContentType is a nullable enum of type ContentType action.ParentContentType maps to a database table which is a nullable int. If ac...

How do I check a MySQL column to make sure it contains a value?

I am trying to select all rows from a database where display = 'Y' and announcement != null. How can I check a column to make sure it contains a value? $qry = "select * from school where display='Y' order by name, announcement, last_update"; ...

MySQL returning an empty field: CONCAT(nonEmpty1,empty2,nonEmpty3) = NULL

I have PHP 5 code accessing a MyISAM table on MySQL 5 server. The query looks like this: SELECT CONCAT(fName1,' ',mName2,' ',lName3) AS userName FROM users WHERE level > 10 When there's no mName filled in, I am expecting output like "fname lname" , but I'm getting "" (empty string) instead (the number of rows returned is co...

Checking database for NULL boolean value

I have a field in a table that is boolean, a range of records have no value (not true or false). How do I write my SQL statement to find these? I have tried the following SQL statements without success: 1) SELECT * FROM table WHERE field = NULL 2) SELECT * FROM table WHERE field != TRUE AND field != FALSE Any help would be greatly ap...

Attached SQL 2000 DB in a SQL 2005 Server, Now getting VB6 App throwing errors

A SQL 2000 db was detached, SQL 2000 was uninstalled. Then SQL 2005 installed in the same machine. Then the database was attached to the newly installed SQL 2005 server. It seemed to work at first but after the users started to poke around, error related to null started to pop. Null values from datetime columns that DID NOT have nulls, a...

When would ShowDialog() return null?

WPF's Window.ShowDialog method returns a nullable boolean. So does CommonDialog.ShowDialog. Now, I understand cases where these would return false (user clicked Cancel or pressed Esc), and when they would return true (code sets Window.DialogResult to true, probably in response to OK being clicked). But null? My first thought is that cl...

compare an object to null!!

I am trying to verify whether an object is null or not and i am using this syntax: void renderSearch(Customer c){ System.out.println("search customer rendering>..."); try { if(!c.equals(null)){ System.out.println("search customer found..."); }else{ ...

SQL Server - Include NULL using UNPIVOT

UNPIVOT will not return NULLs, but I need them in a comparison query. I am trying to avoid using ISNULL the following example (Because in the real sql there are over 100 fields.: Select ID, theValue, column_name From (select ID, ISNULL(CAST([TheColumnToCompare] AS VarChar(1000)), '') as TheColumnToCompare from MyView where The_...

Why can't typed optional arguments have a default of Null?

In ActionScript 3, when you declare an optional argument by giving it a default value, the value null cannot be used on typed arguments. function Action(Param:int=null){ // 1184: Incompatible default value of type Null where int is expected. } function Action(Param:int=0){ // No compiler errors } Any workarounds for this, or g...

How can I change NULL to 0 when getting a single value from a SQL function?

Hi, I have a query that counts the price of all items between two dates. Here is the select statement: SELECT SUM(Price) AS TotalPrice FROM InventoryWHERE (DateAdded BETWEEN @StartDate AND @EndDate) You can assume all of the tables have been set up properly. If I do a select between two dates and there are no items within that date r...

linq 'range variable' problem

Hello all, I have a strange problem when deleteting records using linq, my suspicion is that it has something to do with the range variable (named source). After deleting a record all targets for a customer are retrieved using the following statement: var q = from source in unitOfWork.GetRepository<db_Target>().Find() where source.db...

Null value returned on Count Distinct (pl sql)

Preemptive apologies for the nonsensical table/column names on these queries. If you've ever worked with the DB backend of Remedy, you'll understand. I'm having a problem where a Count Distinct is returning a null value, when I suspect the actual value should be somewhere in the 20's (23, I believe). Below is a series of queries and t...

Counting non-null columns in a rather strange way

I have a table which has 32 columns. 2 of these columns are identity columns and the rest are values. I would like to get the average of all these 30 columns, excluding the null ones. If none of the columns were null, that would have been pretty easy as follows select (val0 + val1 + val2 + ...) / 30 Since I would like to exclude the nu...

Returning struct from a function, how can I check that it is initialized?

I have the following struct in C++: struct routing_entry { unsigned long destSeq; // 32 bits unsigned long nextHop // 32 bits unsigned char hopCount; // 8 bits }; And I have the following function: routing_entry Cnode_router_aodv::consultTable(unsigned int destinationID ) { routing_entry route; if ( routing_table.f...

Postgresql: using 'NULL' value when insert and update rows with prepared statements

Hi guys, sometimes i need to insert into the table some null values, or update them setting the value to NULL. I've read somewhere in the postgresql documentation that this cant be done, but can be tricket with the default value: pg_query("INSERT INTO my_table (col_a, col_b) VALUES ('whatever', default) p.s: i know that in this examp...

Is one of my DB-fields NOT NULL?

I have to deal with a table where there is a set of fields each followed by a second field that will hold a suggested new value until this change is confirmed. It looks a little like this: refID field1 newField1 field2 newField2 ... refID is an ID value that links to a master table. One row in the master table can have ...

How can C# nullable value typed values be set on NHibernate named IQuery parameters?

I am using NHibernate and calling a stored procedure via a named query: <sql-query name="SearchStuff" read-only="true" cacheable="true"> <return class="ResultEntity" /> EXEC [SearchStuff] ?, ?, ? </sql-query> Many of the stored procedure parameters are deliberately nullable - this cannot be changed. The C#: IQuery listQuery =...

SQL LEFT JOIN return 0 rather than NULL

Hi I want to join two tables, with the number of records for each type being counted. If there are no records of that type in the left table I want a 0 to be returned, not a null. How can I do this? Karl ...

(C#) Problems when overloading the == operator

Hello. I overloaded the == operator on my class as follows: public static bool operator ==(Table pt1, Table pt2) { return Compare(pt1, pt2) == 0 && pt1.TableName == pt2.TableName; } Compare will work just as the strcmp does in c++, returning an integer. Problem is that if I do an if (MY_CLASS == null), it will call my == operator...