@@ -105,6 +105,32 @@ def main():
105105 # 1 2024-09-02 10:05:00+08:00 2 15.3 1
106106 print (result )
107107
108+ # There provides a dedicated interface `execute_update` for executing DMLs, including Insert, Delete.
109+ # This interface directly returns the affected rows which might be convenient for some use cases.
110+ #
111+ # Note, Datalayers does not support Update and the development for Delete is in progress.
112+ sql = """
113+ INSERT INTO python.demo (ts, sid, value, flag) VALUES
114+ ('2024-09-03T10:00:00+08:00', 1, 4.5, 0),
115+ ('2024-09-03T10:05:00+08:00', 2, 11.6, 1);
116+ """
117+ #! It's expected that the affected rows is 2.
118+ #! However, the flightsql-dbapi library does not implement the `execute_update` correctly
119+ #! and the returned affected rows is always 0.
120+ affected_rows = client .execute_update (sql )
121+ # The output should be:
122+ # Affected rows: 2
123+ # print("Affected rows: {}".format(affected_rows))
124+
125+ # Checks that the data are inserted successfully.
126+ sql = "SELECT * FROM python.demo where ts >= '2024-09-03T10:00:00+08:00'"
127+ result = client .execute (sql )
128+ # The result should be:
129+ # ts sid value flag
130+ # 0 2024-09-03 10:00:00+08:00 1 4.5 0
131+ # 1 2024-09-03 10:05:00+08:00 2 11.6 1
132+ print (result )
133+
108134
109135if __name__ == "__main__" :
110136 main ()
0 commit comments