Exemple #1
0
		public static bool TableExists(
			SQLiteConnection connection,
			string           tableName
		)
		{
			bool   boolIsTableExists = false;
			string query             = null;

			if (tableName != null)
			{
				using (connection.OpenWrapper())
				{
					query = string.Format(
						"SELECT COUNT(*) FROM [sqlite_master] m WHERE m.[type] = 'table' AND m.[name] = '{0}'",
						tableName
					);

					SqlScalarCommand command = new SqlScalarCommand(
						connection,
						query
					);

					command.Execute(100);

					if ((long)command.Result > 0L)
					{
						boolIsTableExists = true;
					}
				}
			}

			return boolIsTableExists;
		}
        public long GetMaxRequestId()
        {
            lock (this.maxRequestLock)
            {
                if (this.maxRequestCache == null)
                {
                    string sql = string.Format(
                        "SELECT MAX({0}) FROM [{1}]",
                        RequestIdFieldName,
                        TableName
                    );

                    using (this.Connection.OpenWrapper())
                    {
                        SqlScalarCommand command = new SqlScalarCommand(this.Connection, sql);

                        command.Execute(100);

                        object sqlResult = command.Result;

                        if (sqlResult == DBNull.Value)
                        {
                            this.maxRequestCache = 0;
                        }
                        else
                        {
                            this.maxRequestCache = (Int64)sqlResult;
                        }
                    }
                }
                else
                {
                    this.maxRequestCache++;
                }

                return this.maxRequestCache.Value;
            }
        }