protected T ExecuteScalar <T>(
            string sql,
            IEnumerable <QueryParameterInfo> parameters  = null,
            IEnumerable <ParameterValue> parameterValues = null
            )
        {
            T commandResult;

            SqlScalarCommand scalarCommand = new SqlScalarCommand(
                this.Connection,
                sql,
                this.GetParameters(parameters, parameterValues)
                );

            lock (this._tablesLock)
            {
                scalarCommand.Execute(100);

                object sqlResult = scalarCommand.Result;

                commandResult = sqlResult == DBNull.Value
                                        ? default(T)
                                        : (T)sqlResult;
            }

            return(commandResult);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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);
            }
        }