MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestSQLiteIntegration

Function TestSQLiteIntegration

IceFireDB-SQLite/internal/sqlite/db_test.go:90–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestSQLiteIntegration(t *testing.T) {
91 // Create a temporary database file
92 tmpFile := "/tmp/test_sqlite_" + time.Now().Format("20060102150405") + ".db"
93 defer os.Remove(tmpFile)
94
95 // Initialize SQLite database
96 ctx := context.Background()
97 db := InitSQLite(ctx, tmpFile)
98 defer db.Close()
99
100 // Test table creation
101 createSQL := "CREATE TABLE IF NOT EXISTS test_users (id INTEGER PRIMARY KEY, name VARCHAR(50), email VARCHAR(100))"
102 result, err := Exec(createSQL)
103 if err != nil {
104 t.Fatalf("Failed to create table: %v", err)
105 }
106
107 if result.Status != 2 {
108 t.Errorf("Expected status 2 for DML, got %d", result.Status)
109 }
110
111 // Test INSERT
112 insertSQL := "INSERT INTO test_users (name, email) VALUES ('test_user', 'test@example.com')"
113 result, err = Exec(insertSQL)
114 if err != nil {
115 t.Fatalf("Failed to insert data: %v", err)
116 }
117
118 if result.InsertId != 1 {
119 t.Errorf("Expected InsertId 1, got %d", result.InsertId)
120 }
121
122 if result.AffectedRows != 1 {
123 t.Errorf("Expected AffectedRows 1, got %d", result.AffectedRows)
124 }
125
126 // Test SELECT
127 selectSQL := "SELECT * FROM test_users"
128 result, err = Exec(selectSQL)
129 if err != nil {
130 t.Fatalf("Failed to select data: %v", err)
131 }
132
133 if result.Status != 31 {
134 t.Errorf("Expected status 31 for SELECT, got %d", result.Status)
135 }
136
137 if len(result.Fields) != 3 {
138 t.Errorf("Expected 3 fields, got %d", len(result.Fields))
139 }
140
141 if result.AffectedRows != 1 {
142 t.Errorf("Expected 1 row affected, got %d", result.AffectedRows)
143 }
144
145 // Verify field information
146 expectedFields := []string{"id", "name", "email"}
147 for i, field := range result.Fields {

Callers

nothing calls this directly

Calls 3

InitSQLiteFunction · 0.85
ExecFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected