예제 #1
0
        public static void RestoreTable(XmlReader rdr, TableDefn table, bool idCol, Hashtable hash)
        {
            string tablename           = table.TableName;
            string pluralisedTablename = Pluralizer.Pluralize(tablename);

            while (rdr.Read())
            {
                if (rdr.NodeType == XmlNodeType.Whitespace)
                {
                }
                else if (rdr.NodeType == XmlNodeType.Element && rdr.Name == tablename)
                {
                    RestoreRow(rdr, table, idCol, hash);
                }
                else if (rdr.NodeType == XmlNodeType.EndElement && rdr.Name == pluralisedTablename)
                {
                    // End of this table
                    break;
                }
                else
                {
                    throw new Exception("XML format error in RestoreTable.");
                }
            }
        }
예제 #2
0
        public static void BackupTable(string tablename, BackupFile file, TableDefn table)
        {
            file.AppendLine("  <" + Pluralizer.Pluralize(tablename) + ">");

            string query = "SELECT " + table.SelectCols() + " FROM " + tablename + ";";

            IDbConnection dbConn = Connection.Me.GetConnection();

            try
            {
                dbConn.Open();
                IDbCommand dbCmd = dbConn.CreateCommand();
                dbCmd.CommandType = CommandType.Text;
                dbCmd.CommandText = query;

                using (IDataReader rdr = dbCmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        file.AppendLine("    <" + tablename + ">");
                        for (int i = 0; i < rdr.FieldCount; i++)
                        {
                            //Console.WriteLine(rdr.GetName(i) + "=" + rdr.GetValue(i).ToString());
                            string key      = rdr.GetName(i);
                            object fldvalue = rdr.GetValue(i);
                            if (fldvalue != DBNull.Value)
                            {
                                fldvalue = Convert.ChangeType(fldvalue, rdr.GetFieldType(i));
                                string clrtype = table.FindColumn(key).CLRType().Name;
                                if (fldvalue != null)
                                {
                                    file.AppendLine("      <" + key + ">" + FormatValue(fldvalue, clrtype) + "</" + key + ">");
                                }
                            }
                        }
                        file.AppendLine("    </" + tablename + ">");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("There was a problem loading table from query [" + query + "] - " + ex.Message, ex);
            }
            finally
            {
                dbConn.Close();
                dbConn = null;
            }

            file.AppendLine("  </" + Pluralizer.Pluralize(tablename) + ">");
        }
예제 #3
0
 /// Find a table, given it name (which may be pluralied).
 public TableDefn FindTable(string name)
 {
     foreach (TableDefn t in this.Tables)
     {
         if (t.TableName.ToLower() == name.ToLower())
         {
             return(t);
         }
         if (Pluralizer.Pluralize(t.TableName).ToLower() == name.ToLower())
         {
             return(t);
         }
     }
     return(null);
 }