summaryrefslogtreecommitdiffstats
path: root/Doc/includes/sqlite3/sumintwindow.py
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2022-08-31 05:54:54 (GMT)
committerGitHub <noreply@github.com>2022-08-31 05:54:54 (GMT)
commitf7e7bf161aaec5a5cffdcec7c97e1f09e445421b (patch)
treee9d339cca5899de4dd2fed407baad75af2631d96 /Doc/includes/sqlite3/sumintwindow.py
parent8ba22b90cafdf83d26318905a021311c6932d2c0 (diff)
downloadcpython-f7e7bf161aaec5a5cffdcec7c97e1f09e445421b.zip
cpython-f7e7bf161aaec5a5cffdcec7c97e1f09e445421b.tar.gz
cpython-f7e7bf161aaec5a5cffdcec7c97e1f09e445421b.tar.bz2
gh-96414: Inline code examples in sqlite3 docs (#96442)
Diffstat (limited to 'Doc/includes/sqlite3/sumintwindow.py')
-rw-r--r--Doc/includes/sqlite3/sumintwindow.py46
1 files changed, 0 insertions, 46 deletions
diff --git a/Doc/includes/sqlite3/sumintwindow.py b/Doc/includes/sqlite3/sumintwindow.py
deleted file mode 100644
index 0e915d6..0000000
--- a/Doc/includes/sqlite3/sumintwindow.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Example taken from https://www.sqlite.org/windowfunctions.html#udfwinfunc
-import sqlite3
-
-
-class WindowSumInt:
- def __init__(self):
- self.count = 0
-
- def step(self, value):
- """Adds a row to the current window."""
- self.count += value
-
- def value(self):
- """Returns the current value of the aggregate."""
- return self.count
-
- def inverse(self, value):
- """Removes a row from the current window."""
- self.count -= value
-
- def finalize(self):
- """Returns the final value of the aggregate.
-
- Any clean-up actions should be placed here.
- """
- return self.count
-
-
-con = sqlite3.connect(":memory:")
-cur = con.execute("create table test(x, y)")
-values = [
- ("a", 4),
- ("b", 5),
- ("c", 3),
- ("d", 8),
- ("e", 1),
-]
-cur.executemany("insert into test values(?, ?)", values)
-con.create_window_function("sumint", 1, WindowSumInt)
-cur.execute("""
- select x, sumint(y) over (
- order by x rows between 1 preceding and 1 following
- ) as sum_y
- from test order by x
-""")
-print(cur.fetchall())