SQLite and NULL values (1 Viewer)

waeberd

Portal Pro
August 16, 2004
314
1
Fribourg (CH)
Hi guys,

having GREAT FUN writing my plugin, I have a problem. Below you find the routine that reads value out of a SQLiteResultSet.

Works fine but only if the value is not null!

If the value is null, I don't see any exception or error message but the plugin does not appear in the MP-Configuration. Simply filling out the null fields with SQLiteBrowser "fixes" the problem....

How do you handle NULLs?
Or do you simply write empty strings when inserting and assume that there are no null values possible?

Thanks!

Daniel




Code:
static string Get(SQLiteResultSet results,int iRecord,string strColum)
{
  if (null==results) return "";
  if (results.Rows.Count<iRecord) return "";
  ArrayList arr=(ArrayList)results.Rows[iRecord];
  int iCol=0;
  foreach (string columnName in results.ColumnNames)
  {
    if (strColum==columnName)
    {
      return ((string)arr[iCol]).Trim();
    }
    iCol++;
  }
  return "";
}
 

waeberd

Portal Pro
August 16, 2004
314
1
Fribourg (CH)
ok, found it out!

Code:
      return ((string)arr[iCol]).Trim();

Need to add a null-check before this line:

Code:
if (arr[iCol] == null) { return "";}

Thanks & sorry for posting self-resolving topics :D
(C# strings can be null, unlike in Delphi......)

Cheers,

Daniel
 
A

Anonymous

Guest
waeberd said:
Thanks & sorry for posting self-resolving topics :D
(C# strings can be null, unlike in Delphi......)

Well you might have saved another dev some time in the future by posting the question and solution :)
 

Users who are viewing this thread

Top Bottom