本文介绍了SQLiteFunction简单不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一个尝试使用SQLiteFunction从我的C#和ADO.NET code。任何人都可以说为什么我得到这个问题?

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.SQLiteException在System.Data.SQLite.dll发生其他信息:近DEMOITSQLite的错误:语法错误

An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dllAdditional information: SQLite error near "DEMOIT": syntax error

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

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.$c$cplex.com/

SQL:

select replayHash from customData where key='Rating' and String2Int(value) < 8

code:

Code:

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简单不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 17:47