# Table not Accepting Empty String Value

**URL:** <https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424>\
**Category:** Classic Servoy\
**Created:** [August 5, 2011, 9:58pm UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424 "2011-08-05T21:58:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [August 5, 2011, 9:58pm UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424/1 "2011-08-05T21:58:23Z")

</div>

Servoy Version: 5.2.9 - build 1020  
Sybase SQL Anywhere Version 11.0.1.2044

I have a table column delcared as TEXT (varchar) and marked as NOT NULL. If I attempt to save an empty string in this column, the following error is emitted:

> > com.servoy.j2db.dataprocessing.DataException: SQL Anywhere Error -195: Column ‘user\_name’ in table ‘user\_record’ cannot be NULL  
> > Validation failed for ‘user\_name’, with value:  
> > Wrapped java.lang.IllegalArgumentException: Validation failed for ‘user\_name’, with value:

Here is the code that causes the error message:

```auto
var fs = databaseManager.getFoundSet( 'arm_data', 'user_record' )
    
fs.loadAllRecords()

var newRecord = fs.getRecord( fs.newRecord() )  

newRecord.user_name = ''

databaseManager.saveData( newRecord )

```

The Sybase document ([SyBooks Online](http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks258.htm)) states the following for SQL Error -195:

> You have not supplied a value where a value is required. The column definition prohibits NULL values or the column is part of a NOT NULL foreign key.

It appears that a NULL is being passed to SQL Anywhere, but it should be an empty string value. Would someone be kind enough to explain to me what is happening?

Thanks!

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [August 8, 2011, 9:33am UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424/2 "2011-08-08T09:33:59Z")

</div>

empty strings and null are tricky… For example oracle as far as i know see those really as the same thing  
inserting an empty string there (when that is allowed) will set that column to NULL.

I don’t know how sybase works with this situation exactly, but you should just threat null and empty the same it really both nothing…

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [August 8, 2011, 9:19pm UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424/3 "2011-08-08T21:19:37Z")

</div>

> I don’t know how sybase works with this situation exactly…

Sybase says this ([http://manuals.sybase.com/onlinebooks/group-pbarc/conn5/sqlug/@Generic\_\_BookTextView/33271;pt=33136](http://manuals.sybase.com/onlinebooks/group-pbarc/conn5/sqlug/@Generic__BookTextView/33271;pt=33136)):

> Character data is placed in the database using the exact binary representation that is passed from the application.

To prove Sybase’s statement, using Sybase Central only, I created a table called ‘test’ that contains a single character column called ‘test\_char’ marked as NULL. Using SQL INSERT statements, I successfully wrote a non-empty string, empty string, and NULL to the table. Then, using the SQL ALTER statement, I added the NOT NULL constraint and tried the INSERT statements again. The table accepted the non-empty and empty strings but rejected the NULL. Below is the SQL code:

```auto
CREATE TABLE test (test_char varchar(20) )

INSERT INTO test (test_char) VALUES ('Hello, World!')
INSERT INTO test (test_char) VALUES ('')
INSERT INTO test (test_char) VALUES (NULL) <--- ACCEPTED

```

```auto
ALTER TABLE TABLE test
ALTER test_char varchar(20) NOT NULL

INSERT INTO test (test_char) VALUES ('Hello, World!')
INSERT INTO test (test_char) VALUES ('')
INSERT INTO test (test_char) VALUES (NULL) <--- REJECTED

```

It’s only when writing an empty string to a NOT NULL column in Servoy that the problem occurs. Isn’t this a bug?

> …you should just threat null and empty the same it really both nothing.

Okay, now I have a philosophical question regarding SQL database design. You are correct that Oracle treats the NULL and empty string the same, but Oracle appears to be the only database engine that does this. To keep our solution database agnostic, should we then mark all character columns to accept NULL? How do other Servoy developers handle the NULL vs. empty string conumdrum? What is the best practice?

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [August 9, 2011, 7:22am UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424/4 "2011-08-09T07:22:24Z")

</div>

Best practice is what i am saying, threat empty the same as null, both is just nothing…

else try once a workaround:

newRecord()  
record.mynotnullcolumn = “something”;  
record.mynotnullcolumn = “”;  
saveData()

---

<div class="post-metadata">

**Author:** ![kwpsd](https://avatars.discourse-cdn.com/v4/letter/k/bb73d2/32.png) [@kwpsd](https://forum.servoy.com/u/kwpsd)\
**Post date:** [August 9, 2011, 10:52pm UTC](https://forum.servoy.com/t/table-not-accepting-empty-string-value/14424/5 "2011-08-09T22:52:32Z")

</div>

NULL it is! Thanks, Johan.
