MCPcopy Create free account
hub / github.com/MariaDB/server / set_db

Method set_db

sql/sql_class.cc:1636–1671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1634*/
1635
1636bool THD::set_db(const LEX_CSTRING *new_db)
1637{
1638 bool result= 0;
1639 /*
1640 Acquiring mutex LOCK_thd_data as we either free the memory allocated
1641 for the database and reallocating the memory for the new db or memcpy
1642 the new_db to the db.
1643 */
1644 /* Do not reallocate memory if current chunk is big enough. */
1645 if (db.str && new_db->str && db.length >= new_db->length)
1646 {
1647 mysql_mutex_lock(&LOCK_thd_data);
1648 db.length= new_db->length;
1649 memcpy((char*) db.str, new_db->str, new_db->length+1);
1650 mysql_mutex_unlock(&LOCK_thd_data);
1651 }
1652 else
1653 {
1654 const char *org_db= db.str;
1655 const char *tmp= NULL;
1656 if (new_db->str)
1657 {
1658 if (!(tmp= my_strndup(key_memory_THD_db, new_db->str, new_db->length,
1659 MYF(MY_WME | ME_FATAL))))
1660 result= 1;
1661 }
1662
1663 mysql_mutex_lock(&LOCK_thd_data);
1664 db.str= tmp;
1665 db.length= tmp ? new_db->length : 0;
1666 mysql_mutex_unlock(&LOCK_thd_data);
1667 my_free((char*) org_db);
1668 }
1669 PSI_CALL_set_thread_db(db.str, (int) db.length);
1670 return result;
1671}
1672
1673
1674/**

Callers 9

delayed_get_tableFunction · 0.45
my_tz_initFunction · 0.45
mysql_change_db_implFunction · 0.45
gtid_pos_table_creationFunction · 0.45
set_thd_dbFunction · 0.45
udf_initFunction · 0.45
Db_restore_ctxMethod · 0.45
~Db_restore_ctxMethod · 0.45

Calls 2

my_strndupFunction · 0.85
my_freeFunction · 0.85

Tested by

no test coverage detected