Explorar o código

Fix SQL syntax errors

Rod Hynes %!s(int64=11) %!d(string=hai) anos
pai
achega
eefd29deb4
Modificáronse 1 ficheiros con 4 adicións e 3 borrados
  1. 4 3
      psiphon/dataStore.go

+ 4 - 3
psiphon/dataStore.go

@@ -50,7 +50,7 @@ func initDataStore() {
              data blob not null);
 	    create table if not exists serverEntryProtocol
 	        (serverEntryId text not null,
-	         protocol text not null)
+	         protocol text not null);
         create table if not exists keyValue
             (key text not null,
              value text not null);
@@ -159,7 +159,7 @@ func StoreServerEntry(serverEntry *ServerEntry, replaceIfExists bool) error {
 			requiredCapability := strings.TrimSuffix(protocol, "-OSSH")
 			if Contains(serverEntry.Capabilities, requiredCapability) {
 				_, err = transaction.Exec(`
-		            insert or ignore into serverEntryProtocol (id, protocol)
+		            insert or ignore into serverEntryProtocol (serverEntryId, protocol)
 		            values (?, ?);
 		            `, serverEntry.IpAddress, protocol)
 				if err != nil {
@@ -306,7 +306,8 @@ func makeServerEntryWhereClause(
 		} else {
 			whereClause += " where"
 		}
-		whereClause += " exists (select 1 from serverEntryProtocol where protocol = ?)"
+		whereClause +=
+			" exists (select 1 from serverEntryProtocol where protocol = ? and serverEntryId = serverEntry.id)"
 		whereParams = append(whereParams, protocol)
 	}
 	if len(excludeIds) > 0 {