예제 #1
0
        static private void ExportTableData(MySqlConnector conn, StreamWriter writer, BackupOptions options)
        {
            List<string> lstTables = GetObjectList(conn, DbObjectType.TABLE);

            foreach (string table in lstTables)
            {
                if (IsView(conn, table))
                {
                    continue;
                }

                Query query = options.GetTableDataQuery(table);

                using (DataReaderBase reader = (query == null ? conn.ExecuteReader(string.Format(@"SELECT * FROM {0}", table)) : query.ExecuteReader(conn)))
                {
                    while (reader.Read())
                    {
                        writer.Write(string.Format(@"INSERT INTO {0} (", table));
                        for (Int32 idx = 0, count = reader.GetColumnCount(); idx < count; idx++)
                        {
                            if (idx > 0) writer.Write(@",");
                            writer.Write(conn.EncloseFieldName(reader.GetColumnName(idx)));
                        }
                        writer.Write(@") VALUES(");
                        for (Int32 idx = 0, count = reader.GetColumnCount(); idx < count; idx++)
                        {
                            if (idx > 0) writer.Write(@",");
                            writer.Write(conn.PrepareValue(reader[idx]));
                        }
                        writer.Write(string.Format(@") {0}{1}", DELIMITER, NEW_LINE));
                    }
                }
            }
        }
예제 #2
0
 static public bool IsView(MySqlConnector conn, string tableName)
 {
     string sql = string.Format(@"SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = SCHEMA() AND TABLE_NAME = {0}", conn.PrepareValue(tableName));
     return !IsNull(conn.ExecuteScalar(sql));
 }