MCPcopy
hub / github.com/rqlite/rqlite / Test_SQLForceQuery_Error

Function Test_SQLForceQuery_Error

db/db_test.go:785–838  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

783}
784
785func 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
840func Test_SimpleTransaction(t *testing.T) {
841 db, path := mustCreateOnDiskDatabaseWAL()

Callers

nothing calls this directly

Calls 7

ExecuteStringStmtMethod · 0.80
asJSONFunction · 0.70
CloseMethod · 0.65
RemoveMethod · 0.65
ErrorMethod · 0.65
ExecuteMethod · 0.65

Tested by

no test coverage detected