Files
ChuBlog/chusql-engine/test.ghci
T

103 lines
4.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================================
-- ChuSQL DROP TABLE + 统计信息 手测脚本
-- 用法:
-- 1. 另开终端起 Rust server:cd chusql-storage && cargo run --bin chusql-storage
-- 2. GHCi 里执行::script ghci-scripts/drop-table-test.ghci
-- ============================================================================
:set -XOverloadedStrings
import ChuSQL.Storage
import ChuSQL.Storage.IPC
import ChuSQL.Model
import ChuSQL.Engine
import ChuSQL.Syntax.AST
import ChuSQL.Syntax.Parser
-- 辅助:把一条 SQL 字符串跑到底
let runSql sql = case parseQuery sql of { Left e -> putStrLn ("parse error: " ++ e); Right q -> runIPCStorage (runQueryM q) >>= print }
-- ============================================================================
-- 2. 清场:如果 demo3 存在就删掉
-- ============================================================================
putStrLn ">>> [2] cleanup"
runSql "DROP TABLE demo3"
-- ============================================================================
-- 3. 建表
-- ============================================================================
putStrLn ">>> [3] CREATE TABLE"
runSql "CREATE TABLE demo3 (id INT, name TEXT)"
-- ============================================================================
-- 4. describe:列应为 id/name,行数应为 0
-- ============================================================================
putStrLn ">>> [4] describe (row_count should be 0)"
doDescribeTable "demo3"
-- ============================================================================
-- 5. 空表能扫
-- ============================================================================
putStrLn ">>> [5] scan empty table"
runIPCStorage (scan "demo3")
-- ============================================================================
-- 6. 插 3 行
-- ============================================================================
putStrLn ">>> [6] INSERT 3 rows"
runSql "INSERT INTO demo3 (id, name) VALUES (1, 'Alice')"
runSql "INSERT INTO demo3 (id, name) VALUES (2, 'Bob')"
runSql "INSERT INTO demo3 (id, name) VALUES (3, 'Carol')"
-- ============================================================================
-- 7. describe:行数应为 3
-- ============================================================================
putStrLn ">>> [7] describe (row_count should be 3)"
doDescribeTable "demo3"
-- ============================================================================
-- 8. 扫回三行
-- ============================================================================
putStrLn ">>> [8] scan 3 rows"
runIPCStorage (scan "demo3")
-- ============================================================================
-- 9. SQL SELECT,走索引
-- ============================================================================
putStrLn ">>> [9] SELECT WHERE id = 2"
runSql "SELECT name FROM demo3 WHERE id = 2"
-- ============================================================================
-- 10. 重复建表应报错
-- ============================================================================
putStrLn ">>> [10] CREATE TABLE again (should fail)"
runSql "CREATE TABLE demo3 (x INT)"
-- ============================================================================
-- 11. 删表
-- ============================================================================
putStrLn ">>> [11] DROP TABLE"
runSql "DROP TABLE demo3"
-- ============================================================================
-- 12. 删后再查,应报 unknown table
-- ============================================================================
putStrLn ">>> [12a] scan after drop (should fail)"
runIPCStorage (scan "demo3")
putStrLn ">>> [12b] describe after drop (should fail)"
doDescribeTable "demo3"
-- ============================================================================
-- 13. 删不存在的表应报错
-- ============================================================================
putStrLn ">>> [13] DROP TABLE nope (should fail)"
runSql "DROP TABLE nope"
-- ============================================================================
-- 14. 列出所有表,不应含 demo3
-- ============================================================================
putStrLn ">>> [14] list_tables"
doListTables
putStrLn ">>> done. check chusql-storage/data/ for disk state"