()
| 38 | sock.send(msg) |
| 39 | |
| 40 | def main(): |
| 41 | # Start pgsqlite |
| 42 | db_file = tempfile.NamedTemporaryFile(suffix='.db', delete=False) |
| 43 | db_file.close() |
| 44 | db_path = db_file.name |
| 45 | |
| 46 | port = 15445 |
| 47 | print(f"Starting pgsqlite on port {port}") |
| 48 | env = os.environ.copy() |
| 49 | env['RUST_LOG'] = 'info' |
| 50 | pgsqlite_proc = subprocess.Popen([ |
| 51 | '../../target/release/pgsqlite', |
| 52 | '--database', db_path, |
| 53 | '--port', str(port) |
| 54 | ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, env=env) |
| 55 | |
| 56 | time.sleep(1) |
| 57 | |
| 58 | try: |
| 59 | # Connect using raw socket |
| 60 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 61 | sock.connect(('localhost', port)) |
| 62 | |
| 63 | # Send startup message |
| 64 | startup = struct.pack('!HH', 3, 0) # Protocol version 3.0 |
| 65 | startup += b'user\x00postgres\x00' |
| 66 | startup += b'database\x00main\x00\x00' |
| 67 | send_message(sock, None, startup) |
| 68 | |
| 69 | # Read authentication response |
| 70 | while True: |
| 71 | msg_type, body = read_message(sock) |
| 72 | print(f"Received: {msg_type}") |
| 73 | if msg_type == 'Z': # ReadyForQuery |
| 74 | break |
| 75 | |
| 76 | # Create tables |
| 77 | query = b"CREATE TABLE users (id SERIAL PRIMARY KEY, username VARCHAR(50));\x00" |
| 78 | send_message(sock, 'Q', query) |
| 79 | while True: |
| 80 | msg_type, body = read_message(sock) |
| 81 | if msg_type == 'Z': |
| 82 | break |
| 83 | |
| 84 | query = b"CREATE TABLE orders (id SERIAL PRIMARY KEY, customer_id INTEGER, total_amount NUMERIC(12,2));\x00" |
| 85 | send_message(sock, 'Q', query) |
| 86 | while True: |
| 87 | msg_type, body = read_message(sock) |
| 88 | if msg_type == 'Z': |
| 89 | break |
| 90 | |
| 91 | print("\n=== Testing Extended Protocol ===") |
| 92 | |
| 93 | # Parse the exact query that SQLAlchemy uses |
| 94 | stmt_name = b"stmt1\x00" |
| 95 | query = b"SELECT orders.id AS orders_id, orders.customer_id AS orders_customer_id, orders.total_amount AS orders_total_amount FROM orders WHERE $1::INTEGER = orders.customer_id\x00" |
| 96 | param_types = struct.pack('!H', 1) + struct.pack('!I', 23) # 1 param of type INT4 |
| 97 |
no test coverage detected