# -*- coding: utf-8 -*-
"""只操作本程序创建的临时对象；全部数据为合成样本。"""
import os, sys, json, sqlite3, tempfile, pathlib, subprocess, time, socket, stat
from pathlib import Path
def emit(**kw):
    print(json.dumps(kw, ensure_ascii=False, sort_keys=True))
def run(atomic):
    c=sqlite3.connect(':memory:'); c.executescript("CREATE TABLE channels(id PRIMARY KEY,body); CREATE TABLE audit(note TEXT NOT NULL); INSERT INTO channels VALUES(1,'old');")
    c.execute("UPDATE channels SET body='new' WHERE id=1")
    if not atomic: c.commit()
    try: c.execute('INSERT INTO audit VALUES(NULL)'); c.commit()
    except sqlite3.IntegrityError: c.rollback()
    return [c.execute('SELECT body FROM channels').fetchone()[0],c.execute('SELECT count(*) FROM audit').fetchone()[0]]
split=run(False); atomic=run(True); assert split==['new',0] and atomic==['old',0]
emit(split_commit=split,atomic_rollback=atomic)
