(t *testing.T)
| 783 | } |
| 784 | |
| 785 | func Test_SQLForceQuery_Error(t *testing.T) { |
| 786 | db, path := mustCreateOnDiskDatabaseWAL() |
| 787 | defer db.Close() |
| 788 | defer os.Remove(path) |
| 789 | |
| 790 | _, err := db.ExecuteStringStmt("CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)") |
| 791 | if err != nil { |
| 792 | t.Fatalf("failed to create table: %s", err.Error()) |
| 793 | } |
| 794 | |
| 795 | tests := []struct { |
| 796 | sql string |
| 797 | forceQuery bool |
| 798 | exp string |
| 799 | }{ |
| 800 | { |
| 801 | sql: `INSERT INTO foo(id, name) VALUES(1, "fiona") RETURNING name AS`, |
| 802 | forceQuery: true, |
| 803 | exp: `[{"error":"incomplete input"}]`, |
| 804 | }, |
| 805 | { |
| 806 | sql: `INSERT INTO foo(id, name) VALUES(1, "fiona") RETURNING xxx`, |
| 807 | forceQuery: false, |
| 808 | exp: `[{"error":"no such column: xxx"}]`, |
| 809 | }, |
| 810 | { |
| 811 | sql: `INSERT INTO foo(id, name) VALUES(1, "fiona") RETURNING xxx`, |
| 812 | forceQuery: true, |
| 813 | exp: `[{"error":"no such column: xxx"}]`, |
| 814 | }, |
| 815 | { |
| 816 | sql: `INSERT INTO foo(id, name) VALUES(1, "fiona") RETURNING name AS`, |
| 817 | forceQuery: false, |
| 818 | exp: `[{"error":"incomplete input"}]`, |
| 819 | }, |
| 820 | } |
| 821 | for _, test := range tests { |
| 822 | req := &command.Request{ |
| 823 | Statements: []*command.Statement{ |
| 824 | { |
| 825 | Sql: test.sql, |
| 826 | ForceQuery: test.forceQuery, |
| 827 | }, |
| 828 | }, |
| 829 | } |
| 830 | r, err := db.Execute(req, false) |
| 831 | if err != nil { |
| 832 | t.Fatalf("failed to insert records: %s", err.Error()) |
| 833 | } |
| 834 | if exp, got := test.exp, asJSON(r); exp != got { |
| 835 | t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got) |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | func Test_SimpleTransaction(t *testing.T) { |
| 841 | db, path := mustCreateOnDiskDatabaseWAL() |
nothing calls this directly
no test coverage detected