Exemplo n.º 1
0
        /// <summary>
        /// Execute a SQL sentence for INSERT, UPDATE or DELETE.
        /// </summary>
        /// <param name="sql">SQL sentence to execute.</param>
        /// <returns>An integer with the number of affected rows.</returns>
        public static int ExecuteNonQuery(string sql)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(sql, ORMSqliteDriver.Connection))
            {
                ORMSqliteDriver.SetCommandParameters(cmd);

                return(cmd.ExecuteNonQuery());
            }
        }
Exemplo n.º 2
0
        public static byte[] ExecuteBlob(string sql)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(sql, ORMSqliteDriver.Connection))
            {
                ORMSqliteDriver.SetCommandParameters(cmd);

                return((byte[])cmd.ExecuteScalar());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Execute a query command.
        /// </summary>
        /// <param name="sql">SQL sentence to execute.</param>
        /// <returns>A <see cref="DbDataReader"/> instance for data accessing.</returns>
        public static DbDataReader ExecuteReader(string sql)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(sql, ORMSqliteDriver.Connection))
            {
                ORMSqliteDriver.SetCommandParameters(cmd);

                return(cmd.ExecuteReader());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Execute a query and return the values in a <see cref="DataTable"/> instance.
        /// </summary>
        /// <param name="sql">SQL sentence.</param>
        /// <returns>A <see cref="DataTable"/> instance filled with the query results.</returns>
        public static DataTable ExecuteDataTable(string sql)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(sql, ORMSqliteDriver.Connection))
            {
                ORMSqliteDriver.SetCommandParameters(cmd);

                using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd))
                {
                    System.Data.DataTable dt = new System.Data.DataTable();
                    da.Fill(dt);

                    return(dt);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Execute a query command that returns a single <see cref="String"/> value.
        /// </summary>
        /// <param name="sql">SQL sentence to execute.</param>
        /// <param name="defaultValue">Returning value when the query doesn't result any value.</param>
        /// <returns>The resulting <see cref="String"/> value.</returns>
        public static string ExecuteString(string sql, string defaultValue)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(sql, ORMSqliteDriver.Connection))
            {
                ORMSqliteDriver.SetCommandParameters(cmd);

                object res = cmd.ExecuteScalar();
                if (res == null)
                {
                    return(defaultValue);
                }
                else
                {
                    return(res as string);
                }
            }
        }