当前位置:  开发笔记 > 编程语言 > 正文

SQLiteFunction简单不起作用

如何解决《SQLiteFunction简单不起作用》经验,为你挑选了1个好方法。

我试图使用我的C#和ADO.NET代码中的SQLiteFunction.谁能说我为什么会遇到这个问题?

System.Data.SQLite.dll中发生未处理的"System.Data.SQLite.SQLiteException"类型的异常附加信息:"DEMOIT"附近的SQLite错误:语法错误

我使用.NET 3.5 x86与SQLite ADO.NET 1.0.65 - 帮助!

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] ) ;
        }
    }

谢谢!



1> deerchao..:

DEMOIT是一个函数,但您正在使用它,就好像它是一个运算符.试试这个:

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);
        }
    }
}

推荐阅读
有风吹过best
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有