Esempio n. 1
0
        public static void CreateDbStructure(DbConnection conn, ISqlDialect dialect)
        {
            if (dialect.DialectCaps.NestedTransactions)
            {
                using (DbTransaction tran = conn.BeginTransaction())
                {
                    try
                    {
                        DbConnectionExtension.ExecuteScalar(conn, "SELECT COUNT(*) FROM d2dx_info", tran);
                    }
                    catch (Exception)
                    {
                        TestAllowCreateStructure();
                        DbConnectionExtension.ExecuteNonQueries(conn, DatAdmin.DataSources.D2DX.SqlScripts.update_01, dialect, tran, null);
                    }
                    tran.Commit();
                }
            }
            else
            {
                try
                {
                    DbConnectionExtension.ExecuteScalar(conn, "SELECT COUNT(*) FROM d2dx_info");
                }
                catch (Exception)
                {
                    TestAllowCreateStructure();
                    DbConnectionExtension.ExecuteNonQueries(conn, DatAdmin.DataSources.D2DX.SqlScripts.update_01, dialect);
                }
            }

            // handle higher versions
            ProcesssUpdate(2, DatAdmin.DataSources.D2DX.SqlScripts.update_02, conn, dialect);
        }
Esempio n. 2
0
        private void SaveFile(string dbname, int folderid, string filename, string data, string type)
        {
            m_conn.SystemConnection.SafeChangeDatabase(dbname);
            WantStructure(true);
            RemoveFile(dbname, folderid, filename);

            using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
            {
                int?   lastid = DbConnectionExtension.ExecuteScalar <int?>(m_conn.SystemConnection, "SELECT MAX(id) FROM d2dx_file");
                int    id = lastid == null ? 1 : lastid.Value + 1;
                string sqlpar, formpar;
                m_conn.Dialect.CreateNamedParameter("p1", out sqlpar, out formpar);
                cmd.CommandText = String.Format("INSERT INTO d2dx_file (id, folder_id, file_name, data_type, file_data) VALUES ({0}, {1}, '{2}', '{3}', {4})", id, folderid, filename, type, sqlpar);
                DbParameter dbpar = m_conn.DbFactory.CreateParameter();
                dbpar.ParameterName = formpar;
                dbpar.Value         = data;
                cmd.Parameters.Add(dbpar);
                cmd.ExecuteNonQuery();
            }

            //using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
            //{
            //    DbParameter par = m_conn.DbFactory.CreateParameter();
            //    string sqlpar, formpar;
            //    m_conn.Dialect.CreateNamedParameter("p1", out sqlpar, out formpar);
            //    cmd.CommandText = String.Format("UPDATE d2dx_file SET data_type='{0}', file_data={1} WHERE folder_id={2} AND file_name='{3}'", type, sqlpar, folderid, filename);
            //    DbParameter dbpar = m_conn.DbFactory.CreateParameter();
            //    dbpar.ParameterName = formpar;
            //    dbpar.Value = data;
            //    cmd.Parameters.Add(dbpar);
            //    cmd.ExecuteNonQuery();
            //}
        }
Esempio n. 3
0
        //public bool HasFile(string dbname, int folderid, int fileid)
        //{
        //    DbConnectionExtension.SafeChangeDatabase(m_conn.SystemConnection, dbname);
        //    WantStructure(false);
        //    if (m_mode == Mode.Clear) return false;
        //    using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
        //    {
        //        cmd.CommandText = String.Format("SELECT id FROM d2dx_file WHERE folder_id={0} AND id='{1}'", folderid, fileid);
        //        using (DbDataReader reader = cmd.ExecuteReader())
        //        {
        //            return reader.Read();
        //        }
        //    }
        //}

        private void LoadFileData(string dbname, int folderid, string filename, out string data, out string type)
        {
            DbConnectionExtension.SafeChangeDatabase(m_conn.SystemConnection, dbname);
            WantStructure(false);
            using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
            {
                cmd.CommandText = String.Format("SELECT data_type, file_data FROM d2dx_file WHERE folder_id={0} AND file_name='{1}'", folderid, filename);
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        type = reader[0].SafeToString();
                        object val = reader[1];
                        if (val is byte[])
                        {
                            data = Encoding.UTF8.GetString((byte[])val);
                        }
                        else
                        {
                            data = val.SafeToString();
                        }
                        return;
                    }
                    throw new InternalError("DAE-00027 File not found:" + filename);
                }
            }
        }
Esempio n. 4
0
 public void RenameFile(string dbname, int folderid, string filename, string newname)
 {
     DbConnectionExtension.SafeChangeDatabase(m_conn.SystemConnection, dbname);
     WantStructure(true);
     using (DbCommand cmd = m_conn.SystemConnection.CreateCommand())
     {
         cmd.CommandText = String.Format("UPDATE d2dx_file SET file_name='{0}' WHERE folder_id={1} AND file_name='{2}'", newname, folderid, filename);
         cmd.ExecuteNonQuery();
     }
 }
Esempio n. 5
0
 public static bool HasDXStructure(DbConnection conn)
 {
     try
     {
         DbConnectionExtension.ExecuteScalar(conn, "SELECT COUNT(*) FROM d2dx_info");
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 6
0
 private static void ProcesssUpdate(int version, string updateSql, DbConnection conn, ISqlDialect dialect)
 {
     if (Int32.Parse(DbConnectionExtension.ExecuteScalar(conn, "SELECT par_value FROM d2dx_info WHERE par_name='dbversion'").ToString()) < version)
     {
         if (dialect.DialectCaps.NestedTransactions)
         {
             using (DbTransaction tran = conn.BeginTransaction())
             {
                 DbConnectionExtension.ExecuteNonQueries(conn, updateSql, dialect, tran, null);
                 tran.Commit();
             }
         }
         else
         {
             DbConnectionExtension.ExecuteNonQueries(conn, updateSql, dialect);
         }
     }
 }