← cproj

sql example

f682cf4a7bf33dfcb40de728403da6a6d894de0d · ovidiucs · Oct 8, 2019 09:00

+21 · 1 file changed

  • graph/python/sqlite_example.py +21 −0
diff --git a/graph/python/sqlite_example.py b/graph/python/sqlite_example.py
new file mode 100644
index 0000000..256ef62
--- /dev/null
+++ b/graph/python/sqlite_example.py
@@ -0,0 +1,21 @@
+import sqlite3
+
+# 1. Create connection object
+
+conn = sqlite3.connect(":memory:")
+
+# 2. Create cursor object instance
+
+c = conn.cursor()
+
+#3. Create a table
+#a. execute method - perform SQL commands
+c.execute('''CREATE TABLE IF NOT EXISTS foo
+            (date text, trans text, symbol text, qty real, price real)''')
+
+c.execute("INSERT INTO foo VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
+#4. Save the changes
+conn.commit()
+
+# 5. Close the connection
+conn.close()