~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

MergedĀ fromĀ me.

Show diffs side-by-side

added added

removed removed

Lines of Context:
180
180
  Open_tables_state(refresh_version),
181
181
  mem_root(&main_mem_root),
182
182
  lex(&main_lex),
183
 
  db(NULL),
184
183
  client(client_arg),
185
184
  scheduler(NULL),
186
185
  scheduler_arg(NULL),
411
410
  plugin::StorageEngine::closeConnection(this);
412
411
  plugin_sessionvar_cleanup(this);
413
412
 
414
 
  if (db)
415
 
  {
416
 
    free(db);
417
 
    db= NULL;
418
 
  }
419
413
  free_root(&warn_root,MYF(0));
420
414
  free_root(&transaction.mem_root,MYF(0));
421
415
  mysys_var=0;                                  // Safety (shouldn't be needed)
661
655
  LEX_STRING db_str= { (char *) in_db, in_db ? strlen(in_db) : 0 };
662
656
  bool is_authenticated;
663
657
 
664
 
  /*
665
 
    Clear session->db as it points to something, that will be freed when
666
 
    connection is closed. We don't want to accidentally free a wrong
667
 
    pointer if connect failed. Also in case of 'CHANGE USER' failure,
668
 
    current database will be switched to 'no database selected'.
669
 
  */
670
 
  reset_db(NULL, 0);
671
 
 
672
658
  if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
673
659
  {
674
660
    my_error(ER_HANDSHAKE_ERROR, MYF(0), security_ctx.ip.c_str());
753
739
 
754
740
  /* We must allocate some extra memory for the cached query string */
755
741
  query_length= 0; /* Extra safety: Avoid races */
756
 
  query= (char*) memdup_w_gap((unsigned char*) in_packet, in_packet_length, db_length + 1);
 
742
  query= (char*) memdup_w_gap((unsigned char*) in_packet, in_packet_length, db.length() + 1);
757
743
  if (! query)
758
744
    return false;
759
745
 
1126
1112
  if (!dirname_length(exchange->file_name))
1127
1113
  {
1128
1114
    strcpy(path, drizzle_real_data_home);
1129
 
    if (session->db)
1130
 
      strncat(path, session->db, FN_REFLEN-strlen(drizzle_real_data_home)-1);
 
1115
    if (! session->db.empty())
 
1116
      strncat(path, session->db.c_str(), FN_REFLEN-strlen(drizzle_real_data_home)-1);
1131
1117
    (void) fn_format(path, exchange->file_name, path, "", option);
1132
1118
  }
1133
1119
  else
1631
1617
 
1632
1618
bool Session::copy_db_to(char **p_db, size_t *p_db_length)
1633
1619
{
1634
 
  if (db == NULL)
 
1620
  if (db.empty())
1635
1621
  {
1636
1622
    my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
1637
1623
    return true;
1638
1624
  }
1639
 
  *p_db= strmake(db, db_length);
1640
 
  *p_db_length= db_length;
 
1625
  *p_db= strmake(db.c_str(), db.length());
 
1626
  *p_db_length= db.length();
1641
1627
  return false;
1642
1628
}
1643
1629
 
1712
1698
}
1713
1699
 
1714
1700
 
1715
 
bool Session::set_db(const char *new_db, size_t new_db_len)
 
1701
bool Session::set_db(const char *new_db, size_t length)
1716
1702
{
1717
1703
  /* Do not reallocate memory if current chunk is big enough. */
1718
 
  if (db && new_db && db_length >= new_db_len)
1719
 
    memcpy(db, new_db, new_db_len+1);
 
1704
  if (length)
 
1705
    db= new_db;
1720
1706
  else
1721
 
  {
1722
 
    if (db)
1723
 
      free(db);
1724
 
    if (new_db)
1725
 
    {
1726
 
      db= (char *)malloc(new_db_len + 1);
1727
 
      if (db != NULL)
1728
 
      {
1729
 
        memcpy(db, new_db, new_db_len);
1730
 
        db[new_db_len]= 0;
1731
 
      }
1732
 
    }
1733
 
    else
1734
 
      db= NULL;
1735
 
  }
1736
 
  db_length= db ? new_db_len : 0;
1737
 
  return new_db && !db;
 
1707
    db.clear();
 
1708
 
 
1709
  return false;
1738
1710
}
1739
1711
 
1740
1712
 
1821
1793
 
1822
1794
      errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1823
1795
                  , thread_id
1824
 
                  , (db ? db : "unconnected")
 
1796
                  , (db.empty() ? "unconnected" : db.c_str())
1825
1797
                  , sctx->user.empty() == false ? sctx->user.c_str() : "unauthenticated"
1826
1798
                  , sctx->ip.c_str()
1827
1799
                  , (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR)));
1890
1862
  for (table= temporary_tables; table; table= tmp_next)
1891
1863
  {
1892
1864
    tmp_next= table->next;
1893
 
    close_temporary(table, true, true);
 
1865
    close_temporary(table);
1894
1866
  }
1895
1867
  temporary_tables= NULL;
1896
1868
}
1899
1871
  unlink from session->temporary tables and close temporary table
1900
1872
*/
1901
1873
 
1902
 
void Session::close_temporary_table(Table *table,
1903
 
                                    bool free_share, bool delete_table)
 
1874
void Session::close_temporary_table(Table *table)
 
1875
                         
1904
1876
{
1905
1877
  if (table->prev)
1906
1878
  {
1921
1893
    if (temporary_tables)
1922
1894
      table->next->prev= NULL;
1923
1895
  }
1924
 
  close_temporary(table, free_share, delete_table);
 
1896
  close_temporary(table);
1925
1897
}
1926
1898
 
1927
1899
/*
1932
1904
  If this is needed, use close_temporary_table()
1933
1905
*/
1934
1906
 
1935
 
void Session::close_temporary(Table *table, bool free_share, bool delete_table)
 
1907
void Session::close_temporary(Table *table)
1936
1908
{
1937
1909
  plugin::StorageEngine *table_type= table->s->db_type();
1938
1910
 
1939
1911
  table->free_io_cache();
1940
1912
  table->closefrm(false);
1941
1913
 
1942
 
  if (delete_table)
1943
 
    rm_temporary_table(table_type, table->s->path.str);
 
1914
  rm_temporary_table(table_type, table->s->path.str);
1944
1915
 
1945
 
  if (free_share)
1946
 
  {
1947
 
    table->s->free_table_share();
1948
 
    /* This makes me sad, but we're allocating it via malloc */
1949
 
    free(table);
1950
 
  }
 
1916
  table->s->free_table_share();
 
1917
  /* This makes me sad, but we're allocating it via malloc */
 
1918
  free(table);
1951
1919
}
1952
1920
 
1953
1921
/** Clear most status variables. */