Skip to content

Commit 43b6b60

Browse files
Bogdan Degtyariovrsomla1
Bogdan Degtyariov
authored andcommitted
Fix for Bug #29525077 REPORTED TYPE OF INTS IN RESULT SET TOO GENERAL
1 parent c7e6f84 commit 43b6b60

File tree

4 files changed

+87
-8
lines changed

4 files changed

+87
-8
lines changed

cdk/include/mysql/cdk/codec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Format<TYPE_INTEGER> : public Format_base
7777
}
7878

7979
bool is_unsigned() const { return UINT == m_fmt; }
80-
size_t length() { return m_length; }
80+
size_t length() const { return m_length; }
8181

8282
protected:
8383

devapi/result.cc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,26 @@ Type get_api_type(cdk::Type_info type, const common::Format_info &fmt)
110110
}
111111

112112
case cdk::TYPE_INTEGER:
113-
/*
114-
TODO: Report more precise DevAPI type (TINYINT etc) based
115-
on CDK type and encoding format information.
116-
*/
117-
return Type::INT;
113+
{
114+
const common::Format_descr<cdk::TYPE_INTEGER> &fd
115+
= fmt.get<cdk::TYPE_INTEGER>();
116+
117+
size_t f_len = fd.m_format.length();
118+
119+
if (f_len < 5)
120+
return Type::TINYINT;
121+
122+
if (f_len < 8)
123+
return Type::SMALLINT;
124+
125+
if (f_len < 10)
126+
return Type::MEDIUMINT;
127+
128+
if (f_len < 20)
129+
return Type::INT;
130+
131+
return Type::BIGINT;
132+
}
118133

119134
case cdk::TYPE_FLOAT:
120135
{

devapi/tests/bugs-t.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,67 @@ TEST_F(Bugs, not_accumulate)
579579
tbl_remove.orderBy("doc->$.age ASC");
580580
EXPECT_EQ(2, tbl_remove.execute().getAffectedItemsCount());
581581
}
582+
583+
584+
TEST_F(Bugs, bug29525077)
585+
{
586+
SKIP_IF_NO_XPLUGIN;
587+
588+
mysqlx::Session &sess = get_sess();
589+
sess.dropSchema("bug29525077_int_types");
590+
sess.createSchema("bug29525077_int_types");
591+
592+
sess.sql(
593+
"CREATE TABLE bug29525077_int_types.int_types ("
594+
"c1 TINYINT, c2 SMALLINT, c3 MEDIUMINT,"
595+
"c4 INT, c5 BIGINT,"
596+
"c6 TINYINT UNSIGNED, c7 SMALLINT UNSIGNED,"
597+
"c8 MEDIUMINT UNSIGNED, c9 INT UNSIGNED,"
598+
"c10 BIGINT UNSIGNED)"
599+
).execute();
600+
sess.sql(
601+
"INSERT INTO bug29525077_int_types.int_types "
602+
"VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)"
603+
).execute();
604+
mysqlx::Table tab = sess.getSchema("bug29525077_int_types").
605+
getTable("int_types");
606+
607+
auto res = tab.select().execute();
608+
auto columns = &res.getColumns();
609+
col_count_t num_columns = res.getColumnCount();
610+
EXPECT_EQ(10, num_columns);
611+
while (Row r = res.fetchOne())
612+
{
613+
for (col_count_t i = 0; i < num_columns; ++i)
614+
{
615+
auto col_type = (*columns)[i].getType();
616+
switch (i)
617+
{
618+
case 0:
619+
case 5:
620+
EXPECT_EQ(Type::TINYINT, col_type);
621+
break;
622+
case 1:
623+
case 6:
624+
EXPECT_EQ(Type::SMALLINT, col_type);
625+
break;
626+
case 2:
627+
case 7:
628+
EXPECT_EQ(Type::MEDIUMINT, col_type);
629+
break;
630+
case 3:
631+
case 8:
632+
EXPECT_EQ(Type::INT, col_type);
633+
break;
634+
case 4:
635+
case 9:
636+
EXPECT_EQ(Type::BIGINT, col_type);
637+
break;
638+
default:
639+
break;
640+
}
641+
}
642+
}
643+
sess.dropSchema("bug29525077_int_types");
644+
645+
}

devapi/tests/session-t.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ TEST_F(Sess, settings_iterator)
20362036
else if(set.first == SessionOption::SSL_MODE)
20372037
EXPECT_EQ(static_cast<int>(SSLMode::DISABLED), set.second.get<int>());
20382038
else if(set.first == SessionOption::USER)
2039-
EXPECT_EQ(std::string(get_user()), set.second.get<std::string>());
2039+
EXPECT_EQ(std::string(get_user() ? get_user() : ""), set.second.get<std::string>());
20402040
else if(set.first == SessionOption::PWD)
20412041
{
20422042
if (get_password())
@@ -2091,7 +2091,7 @@ TEST_F(Sess, settings_iterator)
20912091
else if(set.first == SessionOption::SSL_MODE)
20922092
EXPECT_EQ(static_cast<int>(SSLMode::DISABLED), set.second.get<int>());
20932093
else if(set.first == SessionOption::USER)
2094-
EXPECT_EQ(std::string(get_user()), set.second.get<std::string>());
2094+
EXPECT_EQ(std::string(get_user() ? get_user() : ""), set.second.get<std::string>());
20952095
else if(set.first == SessionOption::PWD)
20962096
{
20972097
if (get_password())

0 commit comments

Comments
 (0)