Skip to content

Commit 7c228c1

Browse files
committed
mysql表名支持忽略大小写
kbengine#605
1 parent a7250e6 commit 7c228c1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

kbe/src/lib/db_interface/entity_table.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,30 @@ class EntityTable
277277
class EntityTables
278278
{
279279
public:
280+
struct case_insensitive_hasher
281+
{
282+
size_t operator()(const std::string& key) const
283+
{
284+
std::string keyCopy(key);
285+
std::transform(keyCopy.begin(), keyCopy.end(), keyCopy.begin(), tolower);
286+
return std::hash<std::string>()(keyCopy);
287+
}
288+
};
289+
290+
struct case_insensitive_comparer
291+
{
292+
bool operator() (const std::string& x, const std::string& y) const
293+
{
294+
return x.size() == y.size() && kbe_stricmp(x.c_str(), y.c_str()) == 0;
295+
}
296+
};
297+
280298
typedef KBEUnordered_map<std::string, EntityTables> ENTITY_TABLES_MAP;
281299
static ENTITY_TABLES_MAP sEntityTables;
282300
static EntityTables& findByInterfaceName(const std::string& dbInterfaceName);
283301

284-
typedef KBEUnordered_map<std::string, KBEShared_ptr<EntityTable> > TABLES_MAP;
302+
typedef KBEUnordered_map<std::string, KBEShared_ptr<EntityTable>, case_insensitive_hasher, case_insensitive_comparer> TABLES_MAP;
303+
285304
EntityTables();
286305
virtual ~EntityTables();
287306

kbe/src/lib/db_mysql/db_interface_mysql.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ bool DBInterfaceMysql::attach(const char* databaseName)
274274
//-------------------------------------------------------------------------------------
275275
bool DBInterfaceMysql::checkEnvironment()
276276
{
277+
/*
277278
std::string querycmd = "SHOW VARIABLES";
278279
if(!query(querycmd.c_str(), querycmd.size(), true))
279280
{
@@ -315,6 +316,8 @@ bool DBInterfaceMysql::checkEnvironment()
315316
}
316317
317318
return lower_case_table_names;
319+
*/
320+
return true;
318321
}
319322

320323
//-------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)