System.Data.SQLite
Check-in [f5b88735be]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add GetMasterTableName method for use by the SQLiteConnection class.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f5b88735bed1d22a7547894110d5db18bdf88d9d
User & Date: mistachkin 2018-03-09 17:27:02
Context
2018-03-09
17:41
Further improvements to the catalog name and master table name handling in the connection class. check-in: 9bb5fe6f96 user: mistachkin tags: trunk
17:27
Add GetMasterTableName method for use by the SQLiteConnection class. check-in: f5b88735be user: mistachkin tags: trunk
17:25
Add more tests pursuant to ticket [baf42ee135]. check-in: d1b6742e1e user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to System.Data.SQLite/SQLiteConnection.cs.

  1630   1630       private SQLiteCommitCallback _commitCallback;
  1631   1631       private SQLiteTraceCallback _traceCallback;
  1632   1632       private SQLiteRollbackCallback _rollbackCallback;
  1633   1633       #endregion
  1634   1634   
  1635   1635       ///////////////////////////////////////////////////////////////////////////////////////////////
  1636   1636   
         1637  +    private static string GetMasterTableName(
         1638  +        bool temporary
         1639  +        )
         1640  +    {
         1641  +        return temporary ? _tempmasterdb : _masterdb;
         1642  +    }
         1643  +
         1644  +    ///////////////////////////////////////////////////////////////////////////////////////////////
         1645  +
  1637   1646       /// <summary>
  1638   1647       /// This event is raised whenever the database is opened or closed.
  1639   1648       /// </summary>
  1640   1649       public override event StateChangeEventHandler StateChange;
  1641   1650   
  1642   1651       ///////////////////////////////////////////////////////////////////////////////////////////////
  1643   1652   
................................................................................
  5745   5754         tbl.Columns.Add("AUTOINCREMENT", typeof(bool));
  5746   5755         tbl.Columns.Add("UNIQUE", typeof(bool));
  5747   5756   
  5748   5757         tbl.BeginLoadData();
  5749   5758   
  5750   5759         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  5751   5760   
  5752         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         5761  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  5753   5762   
  5754   5763         using (SQLiteCommand cmdTables = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table' OR [type] LIKE 'view'", strCatalog, master), this))
  5755   5764         using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
  5756   5765         {
  5757   5766           while (rdTables.Read())
  5758   5767           {
  5759   5768             if (String.IsNullOrEmpty(strTable) || String.Compare(strTable, rdTables.GetString(2), StringComparison.OrdinalIgnoreCase) == 0)
................................................................................
  5848   5857         tbl.Columns.Add("INTEGRATED", typeof(bool));
  5849   5858         tbl.Columns.Add("INDEX_DEFINITION", typeof(string));
  5850   5859   
  5851   5860         tbl.BeginLoadData();
  5852   5861   
  5853   5862         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  5854   5863   
  5855         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         5864  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  5856   5865   
  5857   5866         using (SQLiteCommand cmdTables = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
  5858   5867         using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
  5859   5868         {
  5860   5869           while (rdTables.Read())
  5861   5870           {
  5862   5871             maybeRowId = false;
................................................................................
  5994   6003         tbl.Columns.Add("TRIGGER_NAME", typeof(string));
  5995   6004         tbl.Columns.Add("TRIGGER_DEFINITION", typeof(string));
  5996   6005   
  5997   6006         tbl.BeginLoadData();
  5998   6007   
  5999   6008         if (String.IsNullOrEmpty(table)) table = null;
  6000   6009         if (String.IsNullOrEmpty(catalog)) catalog = "main";
  6001         -      string master = (String.Compare(catalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6010  +      string master = GetMasterTableName(String.Compare(catalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6002   6011   
  6003   6012         using (SQLiteCommand cmd = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'trigger'", catalog, master), this))
  6004   6013         using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
  6005   6014         {
  6006   6015           while (rd.Read())
  6007   6016           {
  6008   6017             if (String.Compare(rd.GetString(1), triggerName, StringComparison.OrdinalIgnoreCase) == 0
................................................................................
  6049   6058         tbl.Columns.Add("TABLE_ID", typeof(long));
  6050   6059         tbl.Columns.Add("TABLE_ROOTPAGE", typeof(int));
  6051   6060         tbl.Columns.Add("TABLE_DEFINITION", typeof(string));
  6052   6061         tbl.BeginLoadData();
  6053   6062   
  6054   6063         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  6055   6064   
  6056         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6065  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6057   6066   
  6058   6067         using (SQLiteCommand cmd = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT [type], [name], [tbl_name], [rootpage], [sql], [rowid] FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
  6059   6068         using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
  6060   6069         {
  6061   6070           while (rd.Read())
  6062   6071           {
  6063   6072             strItem = rd.GetString(0);
................................................................................
  6115   6124         tbl.Columns.Add("DATE_CREATED", typeof(DateTime));
  6116   6125         tbl.Columns.Add("DATE_MODIFIED", typeof(DateTime));
  6117   6126   
  6118   6127         tbl.BeginLoadData();
  6119   6128   
  6120   6129         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  6121   6130   
  6122         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6131  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6123   6132   
  6124   6133         using (SQLiteCommand cmd = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
  6125   6134         using (SQLiteDataReader rd = (SQLiteDataReader)cmd.ExecuteReader())
  6126   6135         {
  6127   6136           while (rd.Read())
  6128   6137           {
  6129   6138             if (String.Compare(rd.GetString(1), strView, StringComparison.OrdinalIgnoreCase) == 0
................................................................................
  6262   6271         tbl.Columns.Add("INDEX_NAME", typeof(string));
  6263   6272         tbl.Columns.Add("COLLATION_NAME", typeof(string));
  6264   6273         tbl.Columns.Add("SORT_MODE", typeof(string));
  6265   6274         tbl.Columns.Add("CONFLICT_OPTION", typeof(int));
  6266   6275   
  6267   6276         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  6268   6277   
  6269         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6278  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6270   6279   
  6271   6280         tbl.BeginLoadData();
  6272   6281   
  6273   6282         using (SQLiteCommand cmdTables = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
  6274   6283         using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
  6275   6284         {
  6276   6285           while (rdTables.Read())
................................................................................
  6424   6433         tbl.Columns.Add("PRIMARY_KEY", typeof(bool));
  6425   6434         tbl.Columns.Add("EDM_TYPE", typeof(string));
  6426   6435         tbl.Columns.Add("AUTOINCREMENT", typeof(bool));
  6427   6436         tbl.Columns.Add("UNIQUE", typeof(bool));
  6428   6437   
  6429   6438         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  6430   6439   
  6431         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6440  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6432   6441   
  6433   6442         tbl.BeginLoadData();
  6434   6443   
  6435   6444         using (SQLiteCommand cmdViews = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'view'", strCatalog, master), this))
  6436   6445         using (SQLiteDataReader rdViews = cmdViews.ExecuteReader())
  6437   6446         {
  6438   6447           while (rdViews.Read())
................................................................................
  6529   6538         tbl.Columns.Add("FKEY_TO_COLUMN", typeof(string));
  6530   6539         tbl.Columns.Add("FKEY_ON_UPDATE", typeof(string));
  6531   6540         tbl.Columns.Add("FKEY_ON_DELETE", typeof(string));
  6532   6541         tbl.Columns.Add("FKEY_MATCH", typeof(string));
  6533   6542   
  6534   6543         if (String.IsNullOrEmpty(strCatalog)) strCatalog = "main";
  6535   6544   
  6536         -      string master = (String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0) ? _tempmasterdb : _masterdb;
         6545  +      string master = GetMasterTableName(String.Compare(strCatalog, "temp", StringComparison.OrdinalIgnoreCase) == 0);
  6537   6546   
  6538   6547         tbl.BeginLoadData();
  6539   6548   
  6540   6549         using (SQLiteCommand cmdTables = new SQLiteCommand(HelperMethods.StringFormat(CultureInfo.InvariantCulture, "SELECT * FROM [{0}].[{1}] WHERE [type] LIKE 'table'", strCatalog, master), this))
  6541   6550         using (SQLiteDataReader rdTables = cmdTables.ExecuteReader())
  6542   6551         {
  6543   6552           while (rdTables.Read())