|
| 1 | +<?php |
| 2 | + $user = $argv[1]; |
| 3 | + $port = $argv[2]; |
| 4 | + $db = 'doltgres'; |
| 5 | + |
| 6 | + $conn = pg_connect("host = localhost port = $port dbname = $db user = $user") |
| 7 | + or die('Could not connect: ' . pg_result_error()); |
| 8 | + |
| 9 | + $queries = [ |
| 10 | + "create table test (pk int, value int, d1 decimal(9, 3), f1 float, primary key(pk))" => 0, |
| 11 | + "insert into test (pk, value, d1, f1) values (0,0,0.0,0.0)" => 0, |
| 12 | + "select * from test" => 1, |
| 13 | + "call dolt_add('-A');" => 0, |
| 14 | + "call dolt_commit('-m', 'my commit')" => 0, |
| 15 | + "call dolt_checkout('-b', 'mybranch')" => 0, |
| 16 | + "insert into test (pk, value, d1, f1) values (1,1, 123456.789, 420.42)" => 0, |
| 17 | + "call dolt_commit('-a', '-m', 'my commit2')" => 0, |
| 18 | + "call dolt_checkout('main')" => 0, |
| 19 | + "call dolt_merge('mybranch')" => 0, |
| 20 | + "select COUNT(*) FROM dolt_log" => 1 |
| 21 | + ]; |
| 22 | + |
| 23 | + foreach ($queries as $query => $expected) { |
| 24 | + $result = pg_query($conn, $query); |
| 25 | + if (is_bool($result)) { |
| 26 | + if (!$result) { |
| 27 | + echo "LENGTH: {pg_num_rows($result)}\n"; |
| 28 | + echo "QUERY: {$query}\n"; |
| 29 | + echo "EXPECTED: {$expected}\n"; |
| 30 | + echo "RESULT: {$result}"; |
| 31 | + exit(1); |
| 32 | + } |
| 33 | + } else if (pg_num_rows($result) != $expected) { |
| 34 | + echo "LENGTH: {pg_num_rows($result)}\n"; |
| 35 | + echo "QUERY: {$query}\n"; |
| 36 | + echo "EXPECTED: {$expected}\n"; |
| 37 | + echo "RESULT: {$result}"; |
| 38 | + exit(1); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + $result = pg_query($conn, "SELECT * FROM test WHERE pk = 1"); |
| 43 | + assert(1 == pg_num_rows($result)); |
| 44 | + while($row = pg_fetch_assoc($result)) { |
| 45 | + assert(1 == $row['pk']); |
| 46 | + assert(1 == $row['value']); |
| 47 | + assert(123456.789 == $row['d1']); |
| 48 | + assert(420.42 == $row['f1']); |
| 49 | + } |
| 50 | + |
| 51 | + pg_close($conn); |
| 52 | + |
| 53 | + exit(0) |
| 54 | +?> |
0 commit comments