@@ -147,4 +147,40 @@ func main() {
147147 // 2024-09-01 10:05:00 +0800 CST 2 15.30 1
148148 // 2024-09-02 10:05:00 +0800 CST 2 15.30 1
149149 PrintRecords (result )
150+
151+ // Closes the prepared statement to notify releasing resources on server side.
152+ if err = client .ClosePrepared (preparedStmt ); err != nil {
153+ fmt .Println ("Failed to close a prepared statement: " , err )
154+ return
155+ }
156+
157+ // There provides a dedicated interface `execute_update` for executing DMLs, including Insert, Delete.
158+ // This interface directly returns the affected rows which might be convenient for some use cases.
159+ //
160+ // Note, Datalayers does not support Update and the development for Delete is in progress.
161+ sql = `
162+ INSERT INTO go.demo (ts, sid, value, flag) VALUES
163+ ('2024-09-03T10:00:00+08:00', 1, 4.5, 0),
164+ ('2024-09-03T10:05:00+08:00', 2, 11.6, 1);`
165+ affectedRows , err := client .ExecuteUpdate (sql )
166+ if err != nil {
167+ fmt .Println ("Failed to insert data: " , err )
168+ return
169+ }
170+ // The output should be:
171+ // Affected rows: 2
172+ fmt .Println ("Affected rows: " , affectedRows )
173+
174+ // Checks that the data are inserted successfully.
175+ sql = "SELECT * FROM go.demo where ts >= '2024-09-03T10:00:00+08:00'"
176+ result , err = client .Execute (sql )
177+ if err != nil {
178+ fmt .Println ("Failed to scan data: " , err )
179+ return
180+ }
181+ // The result should be:
182+ // ts sid value flag
183+ // 2024-09-03 10:00:00 +0800 CST 1 4.50 0
184+ // 2024-09-03 10:05:00 +0800 CST 2 11.60 1
185+ PrintRecords (result )
150186}
0 commit comments