aboutsummaryrefslogtreecommitdiff
path: root/examples/circle.sql
diff options
context:
space:
mode:
Diffstat (limited to 'examples/circle.sql')
-rw-r--r--examples/circle.sql25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/circle.sql b/examples/circle.sql
new file mode 100644
index 0000000..73e7118
--- /dev/null
+++ b/examples/circle.sql
@@ -0,0 +1,25 @@
+CREATE TEMP TABLE variables(name TEXT PRIMARY KEY, value Text);
+
+INSERT INTO images (width, height) VALUES (6, 6) RETURNING id;
+INSERT INTO variables VALUES ('image_id', last_insert_rowid());
+
+WITH RECURSIVE
+ image_id AS (SELECT value FROM variables WHERE name = 'image_id'),
+ horizontal(x) AS (
+ SELECT width FROM images WHERE id = (SELECT * FROM image_id)
+ UNION ALL
+ SELECT x - 1 FROM horizontal
+ WHERE x > 1
+ ),
+ vertical(y) AS (
+ SELECT height FROM images WHERE id = (SELECT * FROM image_id)
+ UNION ALL
+ SELECT y - 1 FROM vertical
+ WHERE y > 1
+ ),
+ pixels_temp(x, y, r, g, b) AS (
+ SELECT x, y, 255, 0, 0 FROM vertical, horizontal
+ )
+INSERT INTO pixels (image_id, x, y, r, g, b) SELECT (SELECT * FROM image_id), x, y, r, g, b FROM pixels_temp;
+
+DROP TABLE variables;