private ExportItem LoadItem (SqliteDataReader reader)
	{
		return new ExportItem (Convert.ToUInt32 (reader[0]), 
				       Convert.ToUInt32 (reader[1]),
				       Convert.ToUInt32 (reader[2]), 
				       reader[3].ToString (), 
				       reader[4].ToString ());
	}
Example #2
0
            static float[] ReadFromDb(Mono.Data.SqliteClient.SqliteDataReader reader)
            {
                float[] attributeArray = new float[(int)Pathea.AttribType.Max];

                for (int i = (int)Pathea.AttribType.HpMax; i < (int)Pathea.AttribType.Max; i++)
                {
                    Pathea.AttribType a             = (Pathea.AttribType)i;
                    string            attributeName = a.ToString();
                    attributeArray[i] = System.Convert.ToSingle(reader.GetString(reader.GetOrdinal(attributeName)));
                }
                return(attributeArray);
            }
Example #3
0
            public static PropertyList LoadFromDb(Mono.Data.SqliteClient.SqliteDataReader reader)
            {
                float[] attributeArray = ReadFromDb(reader);

                int count = 0;

                for (int i = 0; i < attributeArray.Length; i++)
                {
                    if (Mathf.Abs(attributeArray[i] - 0f) > PETools.PEMath.Epsilon)
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    return(null);
                }

                PropertyList.PropertyValue[] propertys = new PropertyList.PropertyValue[count];

                count = 0;
                for (int i = 0; i < attributeArray.Length; i++)
                {
                    if (Mathf.Abs(attributeArray[i] - 0f) > PETools.PEMath.Epsilon)
                    {
                        propertys[count++] = new PropertyList.PropertyValue()
                        {
                            type  = (Pathea.AttribType)i,
                            value = attributeArray[i]
                        };
                    }
                }

                return(new PropertyList(propertys));
            }
        /// <summary>
        /// Internal function to read a row from a SqliteDataReader to convert
        /// it to a ContentEntry.
        /// </summary>
        /// <param name="reader">The SqliteDataReader to get the information from.</param>
        /// <param name="IncludeImageData">Should image data be included?</param>
        /// <returns>A ContentEntry describing the row returned.</returns>
        private ContentEntry GetEntryFromReader(SqliteDataReader reader, bool IncludeImageData)
        {
            ContentEntry entry = new ContentEntry();

            // read in rows
            try
            {
                entry.ContentID = (uint)(int)reader["contentId"];
            }
            catch (ArgumentOutOfRangeException)
            {
                // no rows, fail out.
                return null;
            }

            entry.Orphan = this.CheckIfRecordIsOrphaned(entry.ContentID);

            DateTime activate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            entry.Activate = activate.AddSeconds((int)reader["activate"]);

            entry.Active = ((int)reader["active"] >= 1);

            if ((int)reader["expire"] > 0)
            {
                DateTime expires = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                entry.Expiry = expires.AddSeconds((int)reader["expire"]);
                entry.Expires = true;
            }
            else
            {
                entry.Expires = false;
            }

            entry.DayParts = (uint)(int)reader["dayparts"];

            entry.contentType = new ContentType((uint)(int)reader["contentType"]);

            entry.Size = (uint)(int)reader["size"];
            entry.ViewCount = (uint)(int)reader["viewcount"];
            entry.ViewLimit = (uint)(int)reader["viewlimit"];
            entry.DisplayAfter = (uint)(int)reader["displayafter"];

            // parse properties.
            String props = (String)reader["props"];
            entry.Properties = new SortedDictionary<string, string>();

            // Provide "sensible default" for mintime, incase the file has errors and it
            // is omitted.
            if (this.MinTimeStoredInSeconds)
            {
                entry.Properties["MinTime"] = "2";
            }
            else
            {
                entry.Properties["MinTime"] = "2000";
            }

            foreach (String prop in props.Split('&'))
            {
                if (prop.Length > 0)
                {
                    String[] pk = prop.Split('=');
                    entry.Properties[pk[0]] = pk[1];
                }
            }

            if (IncludeImageData)
            {
                long fileLength;
                try
                {
                    fileLength = ((byte[])reader["data"]).Length;
                }
                catch (Exception ex)
                {
                    // data blob is empty
                    ex.ToString();
                    fileLength = 0;
                }
                byte[] ddsimage = new byte[fileLength];
                if (fileLength > 0)
                {
                    ddsimage = ((byte[])reader["data"]);
                }

                entry.Data = ddsimage;
            }

            return entry;
        }
		public SqliteDataReader ExecuteReader (CommandBehavior behavior, bool want_results, out int rows_affected)
		{
			SqliteDataReader reader = null;
			SqliteError err = SqliteError.OK;
			IntPtr errMsg = IntPtr.Zero; 
			
			parent_conn.StartExec ();
			
			string msg = "";

			try {
				if (want_results) {
					IntPtr pVm = IntPtr.Zero;
					IntPtr pzTail = IntPtr.Zero;
					if (parent_conn.Version == 3)
						err = Sqlite.sqlite3_prepare (parent_conn.Handle, sql, sql.Length, out pVm, out pVm);
					else
						err = Sqlite.sqlite_compile (parent_conn.Handle, sql, out pzTail, out pVm, out errMsg);
					if (err == SqliteError.OK)
						reader = new SqliteDataReader (this, pVm, parent_conn.Version);
					if (parent_conn.Version == 3)
						err = Sqlite.sqlite3_finalize (pVm, out errMsg);
					else
						err = Sqlite.sqlite_finalize (pVm, out errMsg);
				} else {
					if (parent_conn.Version == 3)
						err = Sqlite.sqlite3_exec (parent_conn.Handle, sql, IntPtr.Zero, IntPtr.Zero, out errMsg);
					else
						err = Sqlite.sqlite_exec (parent_conn.Handle, sql, IntPtr.Zero, IntPtr.Zero, out errMsg);
				}
			} finally {			
				parent_conn.EndExec ();
			}

			if (err != SqliteError.OK) {
				if (errMsg != IntPtr.Zero) {
					msg = Marshal.PtrToStringAnsi (errMsg);
					if (parent_conn.Version != 3)
						Sqlite.sqliteFree (errMsg);
				}
				throw new ApplicationException ("Sqlite error " + msg);
			}
			
			rows_affected = NumChanges ();
			
			return reader;
		}
	private Job LoadItem (SqliteDataReader reader)
	{
		return (Job) Activator.CreateInstance (
				Type.GetType (reader [1].ToString ()), 
				Convert.ToUInt32 (reader[0]), 
				reader[2].ToString (), 
				Convert.ToInt32 (reader[3]), 
				(JobPriority) Convert.ToInt32 (reader[4]),
				true);
	}
Example #7
0
    static void LoadNpcRandomMissionData()
    {
        Mono.Data.SqliteClient.SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("RandNPCMission");
        while (reader.Read())
        {
            NpcMissionData missionData = new NpcMissionData();
            missionData.mCurComMisNum = 0;

            int id = Convert.ToInt32(reader.GetString(reader.GetOrdinal("ID")));
            missionData.m_Rnpc_ID = Convert.ToInt32(reader.GetString(reader.GetOrdinal("RNPC_ID")));

            string   tmp;
            string[] tmplist;


            tmp     = reader.GetString(reader.GetOrdinal("natalplace"));
            tmplist = tmp.Split(',');
            if (tmplist.Length == 3)
            {
                float x = Convert.ToSingle(tmplist[0]);
                float y = Convert.ToSingle(tmplist[1]);
                float z = Convert.ToSingle(tmplist[2]);
                missionData.m_Pos = new Vector3(x, y, z);
            }

            tmp = reader.GetString(reader.GetOrdinal("Rmissionlist"));
            if (tmp != "0")
            {
                missionData.m_RandomMission = Convert.ToInt32(tmp);
            }

            tmp     = reader.GetString(reader.GetOrdinal("missionlist"));
            tmplist = tmp.Split(',');
            for (int i = 0; i < tmplist.Length; i++)
            {
                if (tmplist[i] != "0")
                {
                    missionData.m_MissionList.Add(Convert.ToInt32(tmplist[i]));
                }
            }

            tmp     = reader.GetString(reader.GetOrdinal("RecruitMissionID"));
            tmplist = tmp.Split(',');
            for (int i = 0; i < tmplist.Length; i++)
            {
                if (tmplist[i] != "0")
                {
                    missionData.m_RecruitMissionList.Add(Convert.ToInt32(tmplist[i]));
                }
            }

            missionData.mCompletedMissionCount = Convert.ToInt32(reader.GetString(reader.GetOrdinal("RecruitMissionNum")));

            tmp     = reader.GetString(reader.GetOrdinal("Colony_RecruitMissionID"));
            tmplist = tmp.Split(',');
            for (int i = 0; i < tmplist.Length; i++)
            {
                if (tmplist[i] != "0")
                {
                    missionData.m_CSRecruitMissionList.Add(Convert.ToInt32(tmplist[i]));
                }
            }

            missionData.m_bRandomNpc = true;
            NpcMissionDataRepository.AddMissionData(id, missionData);
        }
    }