summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/client_test.c90
1 files changed, 89 insertions, 1 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 681d4013eec..1e34b5a6f30 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -8112,6 +8112,88 @@ static void test_parse_error_and_bad_length()
fprintf(stdout, "Got error (as expected): '%s'\n", mysql_error(mysql));
}
+
+static void test_subqueries()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ const char *query= "SELECT (SELECT SUM(a+b) FROM t2 where t1.b=t2.b GROUP BY t1.a LIMIT 1) as scalar_s, exists (select 1 from t2 where t2.a/2=t1.a) as exists_s, a in (select a+3 from t2) as in_s, (a-1,b-1) in (select a,b from t2) as in_row_s FROM t1";
+
+ myheader("test_subquery");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,t2");
+ myquery(rc);
+
+ rc= mysql_query(mysql,"CREATE TABLE t1 (a int , b int);");
+ myquery(rc);
+
+ rc= mysql_query(mysql,
+ "insert into t1 values (1,1), (2, 2), (3,3), (4,4), (5,5);");
+ myquery(rc);
+
+ rc= mysql_query(mysql,"create table t2 select * from t1;");
+ myquery(rc);
+
+ stmt= mysql_prepare(mysql, query, strlen(query));
+ mystmt_init(stmt);
+ for (i= 0; i < 3; i++)
+ {
+ rc= mysql_execute(stmt);
+ mystmt(stmt, rc);
+ assert(5 == my_process_stmt_result(stmt));
+ }
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP TABLE t1,t2");
+ myquery(rc);
+}
+
+
+static void test_bad_union()
+{
+ MYSQL_STMT *stmt;
+ const char *query= "SELECT 1, 2 union SELECT 1";
+
+ myheader("test_bad_union");
+
+ stmt= mysql_prepare(mysql, query, strlen(query));
+ assert(stmt == 0);
+ myerror(NULL);
+}
+
+static void test_distinct()
+{
+ MYSQL_STMT *stmt;
+ int rc, i;
+ const char *query= "SELECT count(distinct b), group_concat(a) FROM t1";
+
+ myheader("test_subquery");
+
+ rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql,"CREATE TABLE t1 (a int , b int);");
+ myquery(rc);
+
+ rc= mysql_query(mysql,
+ "insert into t1 values (1,1), (2, 2), (3,3), (4,4), (5,5);");
+ myquery(rc);
+
+ for (i= 0; i < 3; i++)
+ {
+ stmt= mysql_prepare(mysql, query, strlen(query));
+ mystmt_init(stmt);
+ rc= mysql_execute(stmt);
+ mystmt(stmt, rc);
+ assert(1 == my_process_stmt_result(stmt));
+ mysql_stmt_close(stmt);
+ }
+
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+}
+
+
/*
Test for bug#2248 "mysql_fetch without prior mysql_execute hangs"
*/
@@ -8308,6 +8390,7 @@ int main(int argc, char **argv)
test_count= 1;
start_time= time((time_t *)0);
+
client_query(); /* simple client query test */
#if NOT_YET_WORKING
/* Used for internal new development debugging */
@@ -8360,7 +8443,8 @@ int main(int argc, char **argv)
client_use_result(); /* usage of mysql_use_result() */
test_tran_bdb(); /* transaction test on BDB table type */
test_tran_innodb(); /* transaction test on InnoDB table type */
- test_prepare_ext(); /* test prepare with all types conversion -- TODO */
+ test_prepare_ext(); /* test prepare with all types
+ conversion -- TODO */
test_prepare_syntax(); /* syntax check for prepares */
test_field_names(); /* test for field names */
test_field_flags(); /* test to help .NET provider team */
@@ -8417,6 +8501,10 @@ int main(int argc, char **argv)
test_bug2248(); /* BUG#2248 */
test_parse_error_and_bad_length(); /* test if bad length param in
mysql_prepare() triggers error */
+ test_subqueries(); /* repeatable subqueries */
+ test_bad_union(); /* correct setup of UNION */
+ test_distinct(); /* distinct aggregate functions */
+
end_time= time((time_t *)0);
total_time+= difftime(end_time, start_time);