{"action":"created","issue":{"url":"https://api.github.com/repos/mattn/go-sqlite3/issues/259","labels_url":"https://api.github.com/repos/mattn/go-sqlite3/issues/259/labels{/name}","comments_url":"https://api.github.com/repos/mattn/go-sqlite3/issues/259/comments","events_url":"https://api.github.com/repos/mattn/go-sqlite3/issues/259/events","html_url":"https://github.com/mattn/go-sqlite3/issues/259","id":121923932,"number":259,"title":"Where clause not working properly","user":{"login":"Civil","id":844380,"avatar_url":"https://avatars.githubusercontent.com/u/844380?v=3","gravatar_id":"","url":"https://api.github.com/users/Civil","html_url":"https://github.com/Civil","followers_url":"https://api.github.com/users/Civil/followers","following_url":"https://api.github.com/users/Civil/following{/other_user}","gists_url":"https://api.github.com/users/Civil/gists{/gist_id}","starred_url":"https://api.github.com/users/Civil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civil/subscriptions","organizations_url":"https://api.github.com/users/Civil/orgs","repos_url":"https://api.github.com/users/Civil/repos","events_url":"https://api.github.com/users/Civil/events{/privacy}","received_events_url":"https://api.github.com/users/Civil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-12-13T14:58:08Z","updated_at":"2015-12-15T12:58:09Z","closed_at":null,"body":"I'm trying to perform following query (custom fortunes):\r\n```\r\nSELECT id, author, sender, prooflink, text, source, is_approved, timestamp FROM quote WHERE is_approved ORDER BY timestamp DESC LIMIT 10 OFFSET 0\r\n```\r\n\r\nBut I get all records, no matter if \"is_approved\" True or False.\r\n\r\nSchema:\r\n```\r\nCREATE TABLE \"quote\"(\"id\" INTEGER PRIMARY KEY,\"author\" VARCHAR NULL,\"sender\" VARCHAR NULL,\"source\" VARCHAR NOT NULL,\"prooflink\" VARCHAR NOT NULL,\"text\" VARCHAR NOT NULL,\"timestamp\" TIMESTAMP NOT NULL,\"is_approved\" BOOLEAN NOT NULL DEFAULT False)\r\n```\r\n\r\nCode:\r\n```\r\ntype fortune struct {\r\n\tID         uint64    `json:\"id\"`\r\n\tText       string    `json:\"text\"`\r\n\tAuthor     string    `json:\"author\"`\r\n\tSender     string    `json:\"sender\"`\r\n\tProoflink  string    `json:\"prooflink\"`\r\n\tSource     string    `json:\"source\"`\r\n\tIsApproved bool      `json:\"is_approved\"`\r\n\tTimestamp  time.Time `json:\"timestamp\"`\r\n}\r\n\r\nfunc FetchFortunes(number uint64, skip uint64, isApproved int) []fortune {\r\n\tvar fortunes = []fortune{}\r\n\t// TODO: Add cache\r\n\r\n\twhereClause := \"\"\r\n\tif isApproved == 1 {\r\n\t\twhereClause = \"WHERE is_approved\"\r\n\t} else if isApproved == 0 {\r\n\t\twhereClause = \"WHERE NOT(is_approved)\"\r\n\t}\r\n\tquery := \"SELECT id, author, sender, prooflink, text, source, is_approved, timestamp FROM quote \" + whereClause + \" ORDER BY timestamp DESC LIMIT \" + strconv.FormatUint(number, 10) + \" OFFSET \" + strconv.FormatUint(skip, 10)\r\n\tlog.Printf(\"DEBUG: Query: %s\\n\", query)\r\n\trows, err := db.Query(query)\r\n\tif err != nil {\r\n\t\tlog.Printf(\"Error executing query %s\\n\", err)\r\n\t\treturn fortunes\r\n\t}\r\n\tdefer rows.Close()\r\n\r\n\tfor rows.Next() {\r\n\t\tvar fortune fortune\r\n\t\trows.Scan(&fortune.ID, &fortune.Author, &fortune.Sender, &fortune.Prooflink, &fortune.Text, &fortune.Source, &fortune.IsApproved, &fortune.Timestamp)\r\n\r\n\t\tfortunes = append(fortunes, fortune)\r\n\t}\r\n\treturn fortunes\r\n}\r\n```\r\n\r\nQuery that's copied from the debug output works ok in console sqlite client (3.9.2), but with go-sqlite3 it returns all data, as it was performed without \"where\" clause."},"comment":{"url":"https://api.github.com/repos/mattn/go-sqlite3/issues/comments/164756262","html_url":"https://github.com/mattn/go-sqlite3/issues/259#issuecomment-164756262","issue_url":"https://api.github.com/repos/mattn/go-sqlite3/issues/259","id":164756262,"user":{"login":"Civil","id":844380,"avatar_url":"https://avatars.githubusercontent.com/u/844380?v=3","gravatar_id":"","url":"https://api.github.com/users/Civil","html_url":"https://github.com/Civil","followers_url":"https://api.github.com/users/Civil/followers","following_url":"https://api.github.com/users/Civil/following{/other_user}","gists_url":"https://api.github.com/users/Civil/gists{/gist_id}","starred_url":"https://api.github.com/users/Civil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Civil/subscriptions","organizations_url":"https://api.github.com/users/Civil/orgs","repos_url":"https://api.github.com/users/Civil/repos","events_url":"https://api.github.com/users/Civil/events{/privacy}","received_events_url":"https://api.github.com/users/Civil/received_events","type":"User","site_admin":false},"created_at":"2015-12-15T12:58:09Z","updated_at":"2015-12-15T12:58:09Z","body":"I'll try to create database and the code that'll allow you to reproduce that in next week or so."}}