On Thu, 2004-09-23 at 04:44, Matt Howard wrote:
> Kern Sibbald wrote:
>
> > Hello Dan,
> >
> > When I first wrote Bacula, I wasn't too sure how SQL worked (still have
> > certain problems), so when it came to empty filenames rather than
> > dealing with NULLs and other non-compatible horrors of SQL, I simply
> > created a filename with a single space. It works really nice, except it
> > isn't too cool if the filename really has a single space.
> >
> > Now my question: can I safely create a zero length (non-NULL) string in
> > all databases so I can get rid of this silly single space kludge and
> > replace it by a zero length string?
> >
> > I could replace it by a NULL, but that requires some special handling.
> >
> > Best regards, Kern
> >
>
> Looks sane on MySQL ... ( NULL ne "" ne " " )
> See below, in case I'm asleep at the wheel.
>
> ===
> mysql> CREATE DATABASE `test`;
> Query OK, 1 row affected (0.02 sec)
>
> mysql> use test;
> Database changed
>
> mysql> CREATE TABLE Filename (
> -> FilenameId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
> -> Name BLOB NOT NULL,
> -> PRIMARY KEY(FilenameId),
> -> INDEX (Name(30))
> -> );
> Query OK, 0 rows affected (0.01 sec)
>
> mysql> INSERT INTO Filename ( Name ) VALUES ( "" );
> Query OK, 1 row affected (0.00 sec)
>
> mysql> INSERT INTO Filename ( Name ) VALUES ( NULL );
> ERROR 1048: Column 'Name' cannot be null (Sanity test -MH)
>
> mysql> INSERT INTO Filename ( Name ) VALUES ( " " );
> Query OK, 1 row affected (0.00 sec)
>
> mysql> INSERT INTO Filename ( Name ) VALUES ( "foo" );
> Query OK, 1 row affected (0.00 sec)
>
> mysql> SELECT * FROM Filename
> -> ;
> +------------+------+
> | FilenameId | Name |
> +------------+------+
> | 1 | |
> | 2 | |
> | 3 | foo |
> +------------+------+
> 3 rows in set (0.00 sec)
>
> mysql> SELECT * FROM Filename WHERE Name = "";
> +------------+------+
> | FilenameId | Name |
> +------------+------+
> | 1 | |
> +------------+------+
> 1 row in set (0.02 sec)
>
> mysql> SELECT * FROM Filename WHERE Name = NULL;
> Empty set (0.00 sec)
>
> mysql> SELECT * FROM Filename WHERE Name = " ";
> +------------+------+
> | FilenameId | Name |
> +------------+------+
> | 2 | |
> +------------+------+
> 1 row in set (0.00 sec)
> ===
Thanks for confirming that this works correctly on MySQL. I confirmed it
for SQLite, and I'd be *really* surprised if if doesn't work correctly
on PostgreSQL too, since they are very careful about such things ...
|