mirror of
https://github.com/boostorg/mysql.git
synced 2025-05-12 14:11:41 +00:00
Added support for running stored procedures that SELECT data Added support for running multiple semicolon-separated queries Added support for running stored procedures with OUT params Added resultset and resultset_view Fixed documentation typos and wording Refactored object creation in tests Close #133 Close #132 Close #8
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
#!/usr/bin/python3
|
|
#
|
|
# Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
|
|
#
|
|
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
#
|
|
|
|
from subprocess import run, PIPE
|
|
import argparse
|
|
import re
|
|
|
|
|
|
def _parse_order_id(output: str) -> str:
|
|
res = re.search(r'Order: id=([0-9]*)', output)
|
|
assert res is not None
|
|
return res.group(1)
|
|
|
|
|
|
def _parse_line_item_id(output: str) -> str:
|
|
res = re.search(r'Created line item: id=([0-9]*)', output)
|
|
assert res is not None
|
|
return res.group(1)
|
|
|
|
|
|
class Runner:
|
|
def __init__(self, exe: str, host: str) -> None:
|
|
self._exe = exe
|
|
self._host = host
|
|
|
|
def run(self, subcmd: str, *args: str) -> str:
|
|
cmdline = [self._exe, 'sp_user', 'sp_password', self._host, subcmd, *args]
|
|
print(' + ', cmdline)
|
|
res = run(cmdline, check=True, stdout=PIPE)
|
|
print(res.stdout.decode())
|
|
return res.stdout.decode()
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('executable')
|
|
parser.add_argument('host')
|
|
args = parser.parse_args()
|
|
|
|
runner = Runner(args.executable, args.host)
|
|
|
|
runner.run('get-products', 'feast')
|
|
order_id = _parse_order_id(runner.run('create-order'))
|
|
runner.run('get-orders')
|
|
line_item_id = _parse_line_item_id(runner.run('add-line-item', order_id, '1', '5'))
|
|
runner.run('add-line-item', order_id, '2', '2')
|
|
runner.run('add-line-item', order_id, '3', '1')
|
|
runner.run('remove-line-item', line_item_id)
|
|
runner.run('get-order', order_id)
|
|
runner.run('checkout-order', order_id)
|
|
runner.run('complete-order', order_id)
|
|
runner.run('get-orders')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|