Example #1
0
bool TestExtMysql::test_mysql_query() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  Variant row = f_mysql_fetch_assoc(res);
  VS(f_print_r(row, true),
     "Array\n"
     "(\n"
     "    [id] => 1\n"
     "    [name] => test\n"
     ")\n");

  row = f_mysql_fetch_assoc(res);
  VS(f_print_r(row, true),
     "Array\n"
     "(\n"
     "    [id] => 2\n"
     "    [name] => test2\n"
     ")\n");

  row = f_mysql_fetch_assoc(res);
  VS(row, false);
  return Count(true);
}
Example #2
0
static bool CreateTestTable() {
  f_mysql_select_db(TEST_DATABASE);
  f_mysql_query("drop table test");
  return f_mysql_query("create table test (id int not null auto_increment,"
                       " name varchar(255) not null, primary key (id)) "
                       "engine=innodb").toBoolean();
}
Example #3
0
bool TestExtMysql::test_mysql_field_flags() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  VS(f_mysql_field_flags(res, 0), "not_null primary_key auto_increment");
  return Count(true);
}
Example #4
0
bool TestExtMysql::test_mysql_field_type() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  VS(f_mysql_field_type(res, 1), "string");
  return Count(true);
}
Example #5
0
static void CreateMySqlTestTable() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  f_mysql_select_db(TEST_DATABASE);
  f_mysql_query("drop table test");
  f_mysql_query("create table test (id int not null auto_increment,"
                " name varchar(255) not null, primary key (id)) "
                "engine=innodb");
  f_mysql_query("insert into test (name) values ('test'),('test2')");
}
Example #6
0
bool TestExtMysql::test_mysql_field_seek() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  VERIFY(f_mysql_field_seek(res, 1));
  VS(f_mysql_fetch_field(res).toObject()->o_get("name"), "name");
  return Count(true);
}
Example #7
0
bool TestExtMysql::test_mysql_free_result() {
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  VS(f_is_resource("result is a resource"), true);
  f_mysql_free_result(res);
  VS(f_is_resource("result is not a resource after being freed"), false);
  VS(f_mysql_num_rows(res), false);

  return Count(true);
}
Example #8
0
bool TestExtMysql::test_mysql_affected_rows() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);
  VS(f_mysql_affected_rows(), 2);
  return Count(true);
}
Example #9
0
bool TestExtMysql::test_mysql_info() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);
  VS(f_mysql_info(), "Records: 2  Duplicates: 0  Warnings: 0");
  return Count(true);
}
Example #10
0
bool TestExtMysql::test_mysql_warning_count() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  // No warnings from normal operations.
  VERIFY(CreateTestTable());
  VS(f_mysql_warning_count(conn), 0);
  VS(f_mysql_query("INSERT INTO test (name) VALUES ('test'),('test2')"), true);
  VS(f_mysql_warning_count(conn), 0);

  // Dropping a non-existent table with IF EXISTS generates a warning.
  VS(f_mysql_query("DROP TABLE IF EXISTS no_such_table"), true);
  VS(f_mysql_warning_count(conn), 1);

  // Dropping an existing table generates no warnings.
  VS(f_mysql_query("DROP TABLE IF EXISTS test"), true);
  VS(f_mysql_warning_count(conn), 0);

  return Count(true);
}
Example #11
0
bool TestExtMysql::test_mysql_fetch_lengths() {
  Variant conn = f_mysql_connect(TEST_HOSTNAME, TEST_USERNAME, TEST_PASSWORD);
  VERIFY(CreateTestTable());
  VS(f_mysql_query("insert into test (name) values ('test'),('test2')"), true);

  Variant res = f_mysql_query("select * from test");
  Variant row = f_mysql_fetch_row(res);
  Variant lengths = f_mysql_fetch_lengths(res);
  VS(f_print_r(lengths, true),
     "Array\n"
     "(\n"
     "    [0] => 1\n"
     "    [1] => 4\n"
     ")\n");

  // A much more intense test on lengths
  f_mysql_query("drop table testlen");
  VS(f_mysql_query("create table testlen (id int not null auto_increment, "
                   "d decimal(10,5), t tinyint, i int, b bigint, f float, "
                   "db double, y2 year(2), y4 year(4), primary key (id)) "
                   "engine=innodb"), true);
  VS(f_mysql_query("insert into testlen(d, t, i, b, f, db, y2, y4) values"
                   "(.343, null, 384, -1, 03.44, -03.43892874e101, 00, 0000)"),
     true);
  res = f_mysql_query("select * from testlen");
  row = f_mysql_fetch_row(res);
  lengths = f_mysql_fetch_lengths(res);
  VS(f_print_r(lengths, true),
     "Array\n"
     "(\n"
     "    [0] => 1\n"
     "    [1] => 7\n"
     "    [2] => 0\n"
     "    [3] => 3\n"
     "    [4] => 2\n"
     "    [5] => 4\n"
     "    [6] => 16\n"
     "    [7] => 2\n"
     "    [8] => 4\n"
     ")\n");

  return Count(true);
}