SQLiteFunction Simple Not Working(SQLiteFunction 简单不起作用)
问题描述
我试图从我的 C# 和 ADO.NET 代码中使用 SQLiteFunction.谁能说出我为什么会遇到这个问题?
I an attempting to use a SQLiteFunction from my C# and ADO.NET code. Can anyone say why I get this problem?
System.Data.SQLite.dll 中出现System.Data.SQLite.SQLiteException"类型的未处理异常附加信息:DEMOIT"附近的 SQLite 错误:语法错误
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll Additional information: SQLite error near "DEMOIT": syntax error
我正在使用带有 SQLite ADO.NET 1.0.65 的 .NET 3.5 x86 - 帮助!
I am using .NET 3.5 x86 with SQLite ADO.NET 1.0.65 - Help!
public class Program
    {
        static void Main( string[ args )
        {
            test();
        }
        public static void test()
        {
            SQLiteConnection sqlConn = new SQLiteConnection( "Data Source=TestFoods.db;" );
            sqlConn.Open();
            SQLiteCommand sqlCmd = new SQLiteCommand( "PRAGMA integrity_check" , sqlConn);
            sqlCmd.ExecuteNonQuery();
            SQLiteFunction.RegisterFunction( typeof(DEMOIT) );
            sqlCmd = new SQLiteCommand( "SELECT * FROM Foods Where Foods.Name DEMOIT '$butter' " , sqlConn );
            sqlCmd.CommandType = CommandType.Text;
            SQLiteDataAdapter liteAdapter = new SQLiteDataAdapter( sqlCmd );
            DataSet dataSet = new DataSet();
            liteAdapter.Fill( dataSet , "Foods" );
        }
    }
    [SQLiteFunction( Name = "DEMOIT" , Arguments = 1 , FuncType = FunctionType.Scalar )]
    public class DEMOIT : SQLiteFunction
    {
        public override object Invoke( object[] args )
        {
            return Convert.ToString( args[0] ) ;
        }
    }
谢谢!
推荐答案
DEMOIT 是一个函数,但你把它当作一个运算符来使用.试试这个:
DEMOIT is a function, but you are using it as if its an operator. Try this:
sqlCmd = new SQLiteCommand( "SELECT * FROM Foods Where Foods.Name = DEMOIT('$butter')" , sqlConn );
或:
sqlCmd = new SQLiteCommand( "SELECT * FROM Foods Where DEMOIT(Foods.Name) = '$butter'" , sqlConn );
我旧项目的示例 http://war3share.codeplex.com/ :
SQL:
select replayHash from customData where key='Rating' and String2Int(value) < 8
代码:
using System.Data.SQLite;
namespace War3Share.Client.DAL
{
    [SQLiteFunction(Arguments = 1, FuncType = FunctionType.Scalar, Name = "String2Int")]
    class String2Int : SQLiteFunction
    {
        public override object Invoke(object[] args)
        {
            string s = args[0] as string;
            return int.Parse(s);
        }
    }
}
                        这篇关于SQLiteFunction 简单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLiteFunction 简单不起作用
				
        
 
            
        - 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
 - 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
 - 在 LINQ to SQL 中使用 contains() 2022-01-01
 - 使用 rss + c# 2022-01-01
 - CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
 - Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
 - 在 C# 中异步处理项目队列 2022-01-01
 - C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
 - 带问号的 nvarchar 列结果 2022-01-01
 - Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
 
						
						
						
						
						