Index: trunk/db.go
===================================================================
--- trunk/db.go	(revision 421)
+++ trunk/db.go	(revision 422)
@@ -216,16 +216,9 @@
 }
 
-func fromStringPtr(ptr *string) string {
-	if ptr == nil {
-		return ""
-	}
-	return *ptr
-}
-
-func toStringPtr(s string) *string {
-	if s == "" {
-		return nil
-	}
-	return &s
+func toNullString(s string) sql.NullString {
+	return sql.NullString{
+		String: s,
+		Valid:  s != "",
+	}
 }
 
@@ -243,9 +236,9 @@
 	for rows.Next() {
 		var user User
-		var password *string
+		var password sql.NullString
 		if err := rows.Scan(&user.ID, &user.Username, &password, &user.Admin); err != nil {
 			return nil, err
 		}
-		user.Password = fromStringPtr(password)
+		user.Password = password.String
 		users = append(users, user)
 	}
@@ -263,10 +256,10 @@
 	user := &User{Username: username}
 
-	var password *string
+	var password sql.NullString
 	row := db.db.QueryRow("SELECT id, password, admin FROM User WHERE username = ?", username)
 	if err := row.Scan(&user.ID, &password, &user.Admin); err != nil {
 		return nil, err
 	}
-	user.Password = fromStringPtr(password)
+	user.Password = password.String
 	return user, nil
 }
@@ -276,5 +269,5 @@
 	defer db.lock.Unlock()
 
-	password := toStringPtr(user.Password)
+	password := toNullString(user.Password)
 
 	var err error
@@ -347,6 +340,6 @@
 	for rows.Next() {
 		var net Network
-		var name, username, realname, pass, connectCommands *string
-		var saslMechanism, saslPlainUsername, saslPlainPassword *string
+		var name, username, realname, pass, connectCommands sql.NullString
+		var saslMechanism, saslPlainUsername, saslPlainPassword sql.NullString
 		err := rows.Scan(&net.ID, &name, &net.Addr, &net.Nick, &username, &realname,
 			&pass, &connectCommands, &saslMechanism, &saslPlainUsername, &saslPlainPassword,
@@ -355,14 +348,14 @@
 			return nil, err
 		}
-		net.Name = fromStringPtr(name)
-		net.Username = fromStringPtr(username)
-		net.Realname = fromStringPtr(realname)
-		net.Pass = fromStringPtr(pass)
-		if connectCommands != nil {
-			net.ConnectCommands = strings.Split(*connectCommands, "\r\n")
-		}
-		net.SASL.Mechanism = fromStringPtr(saslMechanism)
-		net.SASL.Plain.Username = fromStringPtr(saslPlainUsername)
-		net.SASL.Plain.Password = fromStringPtr(saslPlainPassword)
+		net.Name = name.String
+		net.Username = username.String
+		net.Realname = realname.String
+		net.Pass = pass.String
+		if connectCommands.Valid {
+			net.ConnectCommands = strings.Split(connectCommands.String, "\r\n")
+		}
+		net.SASL.Mechanism = saslMechanism.String
+		net.SASL.Plain.Username = saslPlainUsername.String
+		net.SASL.Plain.Password = saslPlainPassword.String
 		networks = append(networks, net)
 	}
@@ -378,17 +371,17 @@
 	defer db.lock.Unlock()
 
-	netName := toStringPtr(network.Name)
-	netUsername := toStringPtr(network.Username)
-	realname := toStringPtr(network.Realname)
-	pass := toStringPtr(network.Pass)
-	connectCommands := toStringPtr(strings.Join(network.ConnectCommands, "\r\n"))
-
-	var saslMechanism, saslPlainUsername, saslPlainPassword *string
+	netName := toNullString(network.Name)
+	netUsername := toNullString(network.Username)
+	realname := toNullString(network.Realname)
+	pass := toNullString(network.Pass)
+	connectCommands := toNullString(strings.Join(network.ConnectCommands, "\r\n"))
+
+	var saslMechanism, saslPlainUsername, saslPlainPassword sql.NullString
 	if network.SASL.Mechanism != "" {
-		saslMechanism = &network.SASL.Mechanism
+		saslMechanism = toNullString(network.SASL.Mechanism)
 		switch network.SASL.Mechanism {
 		case "PLAIN":
-			saslPlainUsername = toStringPtr(network.SASL.Plain.Username)
-			saslPlainPassword = toStringPtr(network.SASL.Plain.Password)
+			saslPlainUsername = toNullString(network.SASL.Plain.Username)
+			saslPlainPassword = toNullString(network.SASL.Plain.Password)
 			network.SASL.External.CertBlob = nil
 			network.SASL.External.PrivKeyBlob = nil
@@ -466,9 +459,9 @@
 	for rows.Next() {
 		var ch Channel
-		var key *string
+		var key sql.NullString
 		if err := rows.Scan(&ch.ID, &ch.Name, &key, &ch.Detached); err != nil {
 			return nil, err
 		}
-		ch.Key = fromStringPtr(key)
+		ch.Key = key.String
 		channels = append(channels, ch)
 	}
@@ -484,5 +477,5 @@
 	defer db.lock.Unlock()
 
-	key := toStringPtr(ch.Key)
+	key := toNullString(ch.Key)
 
 	var err error
