static void Main(string[] args) { DbConnection databaseConnection = null; try { var databaseName = GetConsoleValue("Input the database name - REQUIRED: (propertyname-value)", true); var user = GetConsoleValue("Input the database user name - REQUIRED: (propertyname-value)", true); var password = GetConsoleValue("Input the database password - REQUIRED: (propertyname-value)", true); var serverInstance = GetConsoleValue("Input the server instance name - REQUIRED: (propertyname-value)", true); var port = GetConsoleValue("Input the database port: (propertyname-value)", false); var databaseProviderPath = GetConsoleValue("Input the database provider dll path - REQUIRED: ", true); var databaseProviderNamespace = GetConsoleValue("Input the database provider namespace - REQUIRED: ", true); var providerInfo = new ProviderInfo(); providerInfo.DatabaseName = new KeyValuePair<string, string>(databaseName.Split('-')[0], databaseName.Split('-')[1]); providerInfo.ServerInstance = new KeyValuePair<string, string>(serverInstance.Split('-')[0], serverInstance.Split('-')[1]); providerInfo.Username = new KeyValuePair<string, string>(user.Split('-')[0], user.Split('-')[1]); providerInfo.Password = new KeyValuePair<string, string>(password.Split('-')[0], password.Split('-')[1]); providerInfo.ProviderNamespace = databaseProviderNamespace; if (!string.IsNullOrEmpty(port)) { providerInfo.Port = new KeyValuePair<string, int>(port.Split('-')[0], Convert.ToInt32(port.Split('-')[1])); } var provider = new DatabaseProvider(databaseProviderPath); databaseConnection = provider.GetDatabaseConnectionInstance(providerInfo); System.Console.WriteLine("Database Connected Succefully!!!"); var types = new List<Type>(); types.AddRange(MappingClasses("Murta.DatabaseGenerator.Console.Models")); var databaseGenerator = new Generator(databaseConnection, types); databaseGenerator.GenerateSchema(); System.Console.WriteLine("Schema generated succefully!!"); } catch (Exception ex) { System.Console.WriteLine("An error ocurred while generating the database schema: " + ex.Message); } finally { if (databaseConnection != null) { if (databaseConnection.State != System.Data.ConnectionState.Closed) { databaseConnection.Close(); databaseConnection.Dispose(); } } } System.Console.ReadKey(); }
public MigrationsTheoryCommand(IMethodInfo method, DatabaseProvider provider, ProgrammingLanguage language) :base(method) { _provider = provider; _language = language; DisplayName = string.Format( "{0} - DatabaseProvider: {1}, ProgrammingLanguage: {2}", DisplayName, _provider, _language); }
/// <summary> /// Получить подключение к базе данных. /// </summary> /// <param name="provider">Провайдер баз данных.</param> /// <param name="connectionString">Строка подключения.</param> /// <returns>Подключение к базе данных</returns> public DatabaseConnectionPair GetConnection(DatabaseProvider provider, string connectionString) { var connection = AllConnections.FirstOrDefault(p => p.Provider == provider && p.ConnectionString.CompareIgnoreCase(connectionString)); if (connection == null) { connection = new DatabaseConnectionPair { Provider = provider, ConnectionString = connectionString }; AddConnection(connection); } return connection; }
public static bool Initialize() { //DatabaseUtil.DBErrorHook = exception => AccountMgr.Instance.Count < 100; //TODO: This is a horrible way to find if we're on production, we need something better than this //DatabaseUtil.DBType = AuthServerConfiguration.DBType; DatabaseProvider = new DatabaseProvider(AuthServerConfiguration.DBServer,AuthServerConfiguration.DBUsername,AuthServerConfiguration.DBPassword,AuthServerConfiguration.DBDatabase,true); //DatabaseUtil.DefaultCharset = DefaultCharset; TODO: Find if this is required anymore /*var asm = typeof(AuthDBMgr).Assembly; try { if (!DatabaseUtil.InitAR(asm)) { return false; } } catch (Exception e) { OnDBError(e); // repeat init DatabaseUtil.InitAR(asm); }*/ // create tables if not already existing /*var count = 0; try { count = Account.GetCount(); } catch { } if (count == 0) { // in case that the CharacterRecord table does not exist -> Recreate schema DatabaseUtil.CreateSchema(); }*/ //NHIdGenerator.InitializeCreators(OnDBError); return true; }
public static TestDatabase InitializeTestDatabase(DatabaseProvider provider, string databaseName) { TestDatabase testDatabase; switch (provider) { case DatabaseProvider.SqlClient: testDatabase = new SqlTestDatabase(databaseName); break; case DatabaseProvider.SqlServerCe: testDatabase = new SqlCeTestDatabase(databaseName); break; default: throw new InvalidOperationException("Unsupported provider"); } testDatabase.EnsureDatabase(); return testDatabase; }
/// <summary> /// 获得区域子节点 /// </summary> /// <param name="kid"></param> /// <returns></returns> public static string getRegionChildrenCount(string kid) { return(DatabaseProvider.GetInstance().getRegionChildrenCount(kid)); }
/// <summary> /// Does the basic job of initialising the db stuff (connection, command) and adding the parameters /// </summary> /// <param name="RequestType">Parameterized SQL text or stored procedure.</param> /// <param name="DatabaseProvider">Database server provider</param> private void Init(DbBaseRequestType RequestType, DatabaseProvider DatabaseProvider) { m_strConnection = DB.ConnectionString; try { // Opens the connection switch (DatabaseProvider) { case DatabaseProvider.MSSQLServer: { m_SqlConnection = new SqlConnection(m_strConnection); break; } case DatabaseProvider.MySQLServer: { m_SqlConnection = new MySqlConnection(m_strConnection); break; } case DatabaseProvider.ODBCSQLServer: { m_SqlConnection = new OdbcConnection(m_strConnection); break; } } m_SqlConnection.Open(); } catch (Exception e) { if(DbBase.ThrowExceptionIsOn) throw e; return; } // Creates a SqlCommand and sets type switch (DatabaseProvider) { case DatabaseProvider.MSSQLServer: { m_SqlCommand = new SqlCommand(m_ProcedureName, (SqlConnection) m_SqlConnection); break; } case DatabaseProvider.MySQLServer: { m_SqlCommand = new MySqlCommand(m_ProcedureName, (MySqlConnection)m_SqlConnection); break; } case DatabaseProvider.ODBCSQLServer: { m_SqlCommand = new OdbcCommand(m_ProcedureName, (OdbcConnection) m_SqlConnection); break; } } if (RequestType == DbBaseRequestType.ParameterizedSQLText) m_SqlCommand.CommandType = CommandType.Text; else if (RequestType == DbBaseRequestType.StoredProcedure) m_SqlCommand.CommandType = CommandType.StoredProcedure; if( this.CommandTimeOut > 0) m_SqlCommand.CommandTimeout = this.CommandTimeOut; // Add a return value parameter by default AddParameter( "RETURN_VALUE", DbType.Int16, ParameterDirection.ReturnValue); // Adds the necessary parameters to the command foreach( IDbDataParameter p in m_HashParameters.Values) m_SqlCommand.Parameters.Add(p); }
/// <summary> /// 更新一条数据 /// </summary> public static void UpdateStaffInfo(StaffInfo model) { DatabaseProvider.GetInstance().UpdateStaffInfo(model); }
/// <summary> /// 获得前几行数据 /// </summary> public static DataSet GetStaffFamilyDataInfoList(int Top, string strWhere, string filedOrder) { return(DatabaseProvider.GetInstance().GetStaffFamilyDataInfoList(Top, strWhere, filedOrder)); }
/// <summary> /// 得到一个对象实体 /// </summary> public static StaffFamilyDataInfo GetStaffFamilyDataInfoModel(int StaffFamilyDataID) { return(DatabaseProvider.GetInstance().GetStaffFamilyDataInfoModel(StaffFamilyDataID)); }
/// <summary> /// 删除一条数据 /// </summary> public static bool DeleteStaffFamilyDataInfo(int StaffFamilyDataID) { return(DatabaseProvider.GetInstance().DeleteStaffFamilyDataInfo(StaffFamilyDataID)); }
/// <summary> /// 更新排序 /// </summary> /// <param name="sCID">源</param> /// <param name="tCID">目标</param> /// <param name="nCIDstr">排序后的目标同级ID串</param> /// <param name="pCID">目标父级编号</param> public static void UpdateRegionOrder(string sCID, string tCID, string nCIDstr, string pCID) { DatabaseProvider.GetInstance().UpdateRegionOrder(sCID, tCID, nCIDstr, pCID); }
/// <summary> /// 开启全文索引 /// </summary> public static void ConfirmFullTextEnable() { DatabaseProvider.GetInstance().ConfirmFullTextEnable(); }
/// <summary> /// 分割主题 /// </summary> /// <param name="postidlist">帖子id列表</param> /// <param name="subject">主题</param> /// <param name="topicId">主题id列表</param> /// <returns>更新记录数</returns> public static int SplitTopics(string postidlist, string subject, string topicId) { //验证要分割的帖子是否为有效PID号 string[] postIdArray = postidlist.Split(','); if (Utils.StrIsNullOrEmpty(postidlist) || !Utils.IsNumericArray(postIdArray)) { return(-1); } int tid = 0; int lastPostId = TypeConverter.StrToInt(postIdArray[postIdArray.Length - 1]); //将要被分割主题的tid TopicInfo originalTopicInfo = Topics.GetTopicInfo(TypeConverter.StrToInt(topicId)); //原主题信息 TopicInfo newTopicInfo = new TopicInfo(); //新主题信息 PostInfo lastPostInfo = Posts.GetPostInfo(originalTopicInfo.Tid, lastPostId); PostInfo firstPostInfo = Posts.GetPostInfo(originalTopicInfo.Tid, TypeConverter.StrToInt(postIdArray[0])); newTopicInfo.Poster = firstPostInfo.Poster; newTopicInfo.Posterid = firstPostInfo.Posterid; newTopicInfo.Postdatetime = Utils.GetDateTime(); newTopicInfo.Displayorder = 0; newTopicInfo.Highlight = ""; newTopicInfo.Digest = 0; newTopicInfo.Rate = 0; newTopicInfo.Hide = 0; newTopicInfo.Special = 0; newTopicInfo.Attachment = 0; newTopicInfo.Moderated = 0; newTopicInfo.Closed = 0; newTopicInfo.Views = 0; newTopicInfo.Fid = originalTopicInfo.Fid; newTopicInfo.Forumname = originalTopicInfo.Forumname; newTopicInfo.Iconid = originalTopicInfo.Iconid; newTopicInfo.Typeid = originalTopicInfo.Typeid; newTopicInfo.Replies = postIdArray.Length - 1; newTopicInfo.Title = Utils.HtmlEncode(subject); newTopicInfo.Lastposterid = lastPostInfo.Posterid; newTopicInfo.Lastpost = lastPostInfo.Postdatetime; newTopicInfo.Lastposter = lastPostInfo.Poster; tid = Topics.CreateTopic(newTopicInfo); DatabaseProvider.GetInstance().UpdatePostTid(postidlist, tid, Data.PostTables.GetPostTableId(tid)); DatabaseProvider.GetInstance().SetPrimaryPost(subject, tid, postIdArray, Discuz.Data.PostTables.GetPostTableId(tid)); newTopicInfo.Tid = tid; newTopicInfo.Lastpostid = lastPostId; if (originalTopicInfo.Lastpostid == lastPostId)//当需要将原主题的最后一个发帖分割走时(即分割列表中有和原主题Lastpostid相同的值) { newTopicInfo.Lastposterid = originalTopicInfo.Posterid; newTopicInfo.Lastpost = originalTopicInfo.Lastpost; newTopicInfo.Lastposter = originalTopicInfo.Poster; DataTable dt = DatabaseProvider.GetInstance().GetLastPostNotInPidList(postidlist, originalTopicInfo.Tid, int.Parse(Posts.GetPostTableId())); originalTopicInfo.Lastpostid = TypeConverter.ObjectToInt(dt.Rows[0]["pid"]); originalTopicInfo.Lastposterid = TypeConverter.ObjectToInt(dt.Rows[0]["Posterid"].ToString()); originalTopicInfo.Lastpost = dt.Rows[0]["Postdatetime"].ToString(); originalTopicInfo.Lastposter = dt.Rows[0]["Poster"].ToString(); } originalTopicInfo.Replies = originalTopicInfo.Replies - postIdArray.Length; Topics.UpdateTopic(originalTopicInfo);//更新原主题的信息 Topics.UpdateTopicReplyCount(originalTopicInfo.Tid); Topics.UpdateTopic(newTopicInfo);//由于数据库中对lastpostid有list约束,所以不能有重复值,则必须在原主题的lastpostid修改之后再次修改才能将数据最终修正完毕 Topics.UpdateTopicReplyCount(tid); return(tid); }
/// <summary> /// 获得数据列表 /// </summary> public static DataSet GetRegionInfoList(string strWhere) { return(DatabaseProvider.GetInstance().GetRegionInfoList(strWhere)); }
/// <summary> /// 得到一个对象实体 /// </summary> public static RegionInfo GetRegionInfoModelLikeName(string rName) { return(DatabaseProvider.GetInstance().GetRegionInfoModelLikeName(rName)); }
/// <summary> /// 得到一个对象实体 /// </summary> public static RegionInfo GetRegionInfoModel(int RegionID) { return(DatabaseProvider.GetInstance().GetRegionInfoModel(RegionID)); }
/// <summary> /// 删除一条数据 /// </summary> public static int DeleteRegionInfo(int RegionID) { return(DatabaseProvider.GetInstance().DeleteRegionInfo(RegionID)); }
/// <summary> /// 更新一条数据 /// </summary> public static int UpdateRegionInfo(RegionInfo model) { return(DatabaseProvider.GetInstance().UpdateRegionInfo(model)); }
/// <summary> /// 是否存在该记录 /// </summary> public static bool ExistsRegionInfo(string rName, int rUpID) { return(DatabaseProvider.GetInstance().ExistsRegionInfo(rName, rUpID)); }
public static bool Initialize() { if (!Initialized) { Initialized = true; DatabaseProvider = new DatabaseProvider(RealmServerConfiguration.DBContentConnectionString,false); // We don't want to map any of the class maps, this will duplicate the maps from the world db & we don't need them anyway } //DatabaseUtil.DBErrorHook = exception => CharacterRecord.GetCount() < 100; //DatabaseUtil.DBType = RealmServerConfiguration.DBType; //DatabaseUtil.ConnectionString = RealmServerConfiguration.DBConnectionString; //DatabaseUtil.DefaultCharset = DefaultCharset; /* var asm = typeof(RealmDBMgr).Assembly; try { if (!DatabaseUtil.InitAR(asm)) { return false; } } catch (Exception e) { // repeat init OnDBError(e); try { if (!DatabaseUtil.InitAR(asm)) { return false; } } catch (Exception e2) { LogUtil.ErrorException(e2, true, "Failed to initialize the Database."); } } } // Create tables if not already existing: // NHibernate wraps up all added Persistors once the first connection to the DB is established // which again happens during the first query to the DB - The line to check for any existing Characters. // After the first query, you cannot register any further types. var count = 0; try { count = CharacterRecord.GetCount(); } catch { } if (count == 0) { // in case that the CharacterRecord table does not exist -> Recreate schema DatabaseUtil.CreateSchema(); }*/ //NHIdGenerator.InitializeCreators(OnDBError); RealmServer.InitMgr.SignalGlobalMgrReady(typeof(RealmContentDBMgr)); return true; }
/// <summary> /// 创建搜索缓存 /// </summary> /// <param name="cacheinfo">搜索缓存信息</param> /// <returns>搜索缓存id</returns> public static int CreateSearchCache(SearchCacheInfo cacheinfo) { return(DatabaseProvider.GetInstance().CreateSearchCache(cacheinfo)); }
public static bool UpdateStaffFamilyDataInfoByJson(StaffFamilyDataJson FamilyDataJson, int StaffID) { return(DatabaseProvider.GetInstance().UpdateStaffFamilyDataInfoByJson(FamilyDataJson, StaffID)); }
/// <summary> /// 是否存在该记录 /// </summary> public static bool ExistsStaffDataInfo(int StaffID) { return(DatabaseProvider.GetInstance().ExistsStaffDataInfo(StaffID)); }
/// <summary> /// 删除一条数据 /// </summary> public static bool DeleteStaffFamilyDataInfoList(string StaffFamilyDataIDlist) { return(DatabaseProvider.GetInstance().DeleteStaffFamilyDataInfoList(StaffFamilyDataIDlist)); }
public static StaffDataInfo GetStaffDataInfoModelByStaffID(int StaffID) { return(DatabaseProvider.GetInstance().GetStaffDataInfoModelByStaffID(StaffID)); }
/// <summary> /// 获得数据列表 /// </summary> public static DataSet GetStaffFamilyDataInfoList(string strWhere) { return(DatabaseProvider.GetInstance().GetStaffFamilyDataInfoList(strWhere)); }
/// <summary> /// 是否存在该记录 /// </summary> public static bool ExistsStaffEduDataInfo(int StaffID, string eDate, string eSchools) { return(DatabaseProvider.GetInstance().ExistsStaffEduDataInfo(StaffID, eDate, eSchools)); }
/// <summary> /// 分页获取数据列表 /// </summary> public static DataTable GetStaffFamilyDataInfoList(int PageSize, int PageIndex, string strWhere, out int pagetotal, int OrderType, string showFName) { return(DatabaseProvider.GetInstance().GetStaffFamilyDataInfoList(PageSize, PageIndex, strWhere, out pagetotal, OrderType, showFName)); }
/// <summary> /// 是否存在该记录 /// </summary> public static bool ExistsStaffInfo(string sName) { return(DatabaseProvider.GetInstance().ExistsStaffInfo(sName)); }
private static void dumpTable(TextWriter tw, Cinar.Database.Table tbl, DatabaseProvider dbProvider) { if (tbl == null) throw new Exception("No such table."); string delimitL = "[", delimitR = "]"; switch (dbProvider) { case DatabaseProvider.PostgreSQL: delimitL = "\""; delimitR = "\""; break; case DatabaseProvider.MySQL: delimitL = "`"; delimitR = "`"; break; case DatabaseProvider.SQLServer: delimitL = "["; delimitR = "]"; break; default: break; } string fields = delimitL + String.Join(delimitR + ", " + delimitL, tbl.Columns.ToStringArray()) + delimitR; string sql = String.Format("insert into {2}{0}{3} ({1}) values ({{0}});", tbl.Name, fields, delimitL, delimitR); DataTable dt = Provider.Database.GetDataTable("select * from [" + tbl.Name + "]"); foreach (DataRow dr in dt.Rows) { string[] values = new string[tbl.Columns.Count]; for (int i = 0; i < tbl.Columns.Count; i++) { string fieldName = tbl.Columns[i].Name; if (dt.Columns[i].DataType == typeof(bool)) values[i] = dr.IsNull(fieldName) ? "null" : "'" + (dr[tbl.Columns[i].Name].Equals(true) ? 1 : 0) + "'"; else if (dt.Columns[i].DataType == typeof(DateTime)) values[i] = dr.IsNull(fieldName) ? "null" : "'" + ((DateTime)dr[tbl.Columns[i].Name]).ToString("yyyy-MM-dd HH:mm") + "'"; else values[i] = dr.IsNull(fieldName) ? "null" : "'" + dr[tbl.Columns[i].Name].ToString().Replace("'", "''").Replace("\\", "\\\\").Replace("\n", "\\n").Replace("\r", "\\r") + "'"; } tw.Write(sql, String.Join(", ", values)); tw.WriteLine(); } }
private void ProviderOnCategoryAdded(DatabaseProvider sender, EventArgs eventArgs) { OnPropertyChanged("Categories"); }
public DataProviderTests( ) { DataProvider = new DatabaseProvider ( ); }
public static DataTable geAreaClassList(int ParentID) { return(DatabaseProvider.GetInstance().geAreaClassList(ParentID)); }
public static bool AddStaffEduDataInfoByJson(StaffEduDataJson EduDataJson) { return(DatabaseProvider.GetInstance().AddStaffEduDataInfoByJson(EduDataJson)); }
public static DataTable GetAreaDetails(int AreaClassID) { return(DatabaseProvider.GetInstance().GetAreaDetails(AreaClassID)); }
public MigrationsTheoryCommand(ITestCommand innerCommand, DatabaseProvider provider, ProgrammingLanguage language) { _innerCommand = innerCommand; _provider = provider; _language = language; }
/// <summary> /// 是否存在该记录 /// </summary> public static bool ExistsStaffFamilyDataInfo(int StaffID, string fName, string fTitle) { return(DatabaseProvider.GetInstance().ExistsStaffFamilyDataInfo(StaffID, fName, fTitle)); }
private void ProviderOnMilestoneAdded(DatabaseProvider sender, EventArgs eventArgs) { OnPropertyChanged("Milestones"); }
/// <summary> /// 增加一条数据 /// </summary> public static int AddStaffFamilyDataInfo(StaffFamilyDataInfo model) { return(DatabaseProvider.GetInstance().AddStaffFamilyDataInfo(model)); }
private void FilterApplied(DatabaseProvider sender, EventArgs e) { var filteredItems = AllItems.Where(i=> i.Date >= sender.FromDateTime && i.Date <= sender.ToDateTime && i.ItemType != FinanceItemType.Planned); var planned = AllItems.Where(i => i.ItemType == FinanceItemType.Planned); if (sender.SelectedMilestone.Id != 0) { filteredItems = filteredItems.Where(i => i.Milestone == sender.SelectedMilestone.Name); planned = planned.Where(i => i.Milestone == sender.SelectedMilestone.Name); } if (sender.SelectedCategory.Id != 0) { filteredItems = filteredItems.Where(i => i.Category == sender.SelectedCategory.Name); planned = planned.Where(i => i.Category == sender.SelectedCategory.Name); } Items = new ObservableCollection<FinanceItemViewModel>(filteredItems.Select(i => new FinanceItemViewModel(i))); PlannedItems = new ObservableCollection<PlannedItemViewModel>(planned.Select(p => new PlannedItemViewModel(p))); SetBalances(); }
public static bool AddStaffFamilyDataInfoByJson(StaffFamilyDataJson FamilyDataJson) { return(DatabaseProvider.GetInstance().AddStaffFamilyDataInfoByJson(FamilyDataJson)); }
public VariantAttribute(DatabaseProvider provider, ProgrammingLanguage language) { DatabaseProvider = provider; ProgrammingLanguage = language; }
/// <summary> /// 更新一条数据 /// </summary> public static bool UpdateStaffFamilyDataInfo(StaffFamilyDataInfo model) { return(DatabaseProvider.GetInstance().UpdateStaffFamilyDataInfo(model)); }