コード例 #1
0
        /// <summary>
        /// Fetches the complete set of elements and returns this set as an IEnumerable.
        /// </summary>
        /// <returns>the set fetched</returns>
        public override IEnumerable <SalesOrderHeader> FetchSet()
        {
            var headers   = new List <SalesOrderHeader>();
            var dbFactory = new PetaPoco.Database(ConnectionStringToUse, "System.Data.SqlClient");

            dbFactory.OpenSharedConnection();
            headers = dbFactory.Fetch <SalesOrderHeader>(CommandText);
            dbFactory.CloseSharedConnection();
            return(headers);
        }
コード例 #2
0
        /// <summary>
        /// Fetches the individual element
        /// </summary>
        /// <param name="key">The key of the element to fetch.</param>
        /// <returns>The fetched element, or null if not found</returns>
        public override SalesOrderHeader FetchIndividual(int key)
        {
            SalesOrderHeader toReturn = null;

            var dbFactory = new PetaPoco.Database(ConnectionStringToUse, "System.Data.SqlClient");

            dbFactory.OpenSharedConnection();
            toReturn = dbFactory.First <SalesOrderHeader>(CommandText + " where SalesOrderId=@0", key);
            dbFactory.CloseSharedConnection();
            return(toReturn);
        }
コード例 #3
0
        /// <summary>
        /// Fetches the complete set of elements and returns this set as an IEnumerable.
        /// </summary>
        /// <returns>the set fetched</returns>
        public override IEnumerable <SalesOrderHeader> FetchSet()
        {
            var headers   = new List <SalesOrderHeader>();
            var dbFactory = new PetaPoco.Database(ConnectionStringToUse, "System.Data.SqlClient");

            dbFactory.OpenSharedConnection();
            dbFactory.EnableAutoSelect    = false;
            dbFactory.EnableNamedParams   = false;
            dbFactory.ForceDateTimesToUtc = false;
            headers = dbFactory.Fetch <SalesOrderHeader>(CommandText);
            dbFactory.CloseSharedConnection();
            return(headers);
        }
コード例 #4
0
        /// <summary>
        /// Fetches the individual element
        /// </summary>
        /// <param name="key">The key of the element to fetch.</param>
        /// <returns>The fetched element, or null if not found</returns>
        public override SalesOrderHeader FetchIndividual(int key)
        {
            SalesOrderHeader toReturn = null;
            var dbFactory             = new PetaPoco.Database(ConnectionStringToUse, "System.Data.SqlClient");

            dbFactory.OpenSharedConnection();
            dbFactory.EnableAutoSelect    = false;
            dbFactory.EnableNamedParams   = false;
            dbFactory.ForceDateTimesToUtc = false;
            toReturn = dbFactory.First <SalesOrderHeader>(CommandText + " where SalesOrderId=@0 ", key);
            dbFactory.CloseSharedConnection();
            return(toReturn);
        }
コード例 #5
0
ファイル: Tests.cs プロジェクト: kakakakaka1230/PetaPoco
		public void CreateDB()
		{
			db = new Database(_connectionStringName);
			db.OpenSharedConnection();		// <-- Wow, this is crucial to getting SqlCE to perform.
			db.Execute(Utils.LoadTextResource(string.Format("PetaPoco.Tests.{0}_init.sql", _connectionStringName)));
		}
コード例 #6
0
ファイル: DataSource.cs プロジェクト: Srid68/Priya.InfoList
        private static Database HaveDb()
        {
			string message = "";
			if ((UseFileSystem == false) && (_db == null))
			{
				InitDb();

				string rootPath = IOManager.RootDirectory;
				string dataPath = IOManager.Combine(rootPath, "App_Data");
				if (ConnectionString.Contains("|DataDirectory|") == true)
				{
					ConnectionString = ConnectionString.Replace("|DataDirectory|", dataPath + IOManager.DirectorySeparator);
				}
				bool checkDb = true;
				if ((ProviderNameFactory.ToUpper() == AppCommon.SQLiteProviderNameFactory.ToUpper()) && (ConnectionString.Contains("AutoFill") == false))
				{
						string sqliteDbPath = "";
					int idxOfSemiColon =ConnectionString.IndexOf(";");
					if (idxOfSemiColon > -1)
					{
						int idxOfEqual = ConnectionString.IndexOf("=");
						sqliteDbPath = ConnectionString.Substring(idxOfEqual + 1, idxOfSemiColon - idxOfEqual -1);
					}
					else
					{
						sqliteDbPath = ConnectionString.Substring(ConnectionString.IndexOf("=") + 1);
					}
					if (IOManager.CachedFileExists(sqliteDbPath, true, true) ==false)
					{
						checkDb =false ;
						LogManager.Log(LogLevel.Critical, "DataSource-HaveDb", "Sqlite Db Not found in Path [" + sqliteDbPath + "]");
					}                       
				}
				if (checkDb == true)
				{
					_db = DataStore.HaveDb(ConnectionString, ProviderNameFactory, out message);
					if (_db != null) {
                        _db.OnDBException -= new PetaPoco.DBException(OnDBException);
                        _db.OnDBException += new PetaPoco.DBException(OnDBException);
                        if (ProviderNameFactory == AppCommon.SQLiteProviderNameFactory)
                        {
                            _db.KeepConnectionAlive = true;
                            UseSharedConnection = true;
                            //_db.Execute("PRAGMA journal_mode=WAL;");
                            //_db.Execute("PRAGMA journal_mode=DELETE;");
                        }
                        if (ProviderNameFactory == AppCommon.MySQLProviderNameFactory)
                        {
                            _db.KeepConnectionAlive = false;
                            UseSharedConnection = false;
                            //_db.Execute("set wait_timeout=28800");
                            //_db.Execute("set interactive_timeout=28800");
                            //_db.Execute("set net_write_timeout=999");
                        }
                        if (UseSharedConnection == true)
                        {
                            _db.OpenSharedConnection();
                        }
					}
				}
			}
			if (_db == null) {
				if (UseFileSystem ==false)
				{
					LogManager.Log(LogLevel.Critical, "Priya.InfoList.DataSource-HaveDb", "Have Db is false for " + DbName + "[" + message + "]");
				}
				else
				{
					LogManager.Log(LogLevel.Critical, "Priya.InfoList.DataSource-HaveDb", "Have Db is false for " + DbName + ". Use FileSystem is true");
				}
			}
            return _db;
        }