解决SQLite异常:library routine called out of sequence

转载 2017年01月03日 11:17:46
在平常的练习中出现了这样的问题,在网上搜寻了下,发现没有什么确定的答案。

却发现:

Error Code SQLITE_MISUSE (21) "Library routine called out of sequence"

The SQLITE_MISUSE error code is returned when you misuse the SQLitelibrary in some way. SQLite does not guarantee that it will detectmisuse, so you should not depend on this behavior in any way. TheSQLITE_MISUSE error code is intended to help you find the bugs inyour code.

Here are some possible causes of SQLITE_MISUSE:

  1. Calling any API routine with an sqlite3* pointer that was not obtained from sqlite3_open() or sqlite3_open16() or which has already been closed by sqlite3_close().
  2. Trying to use the same database connection at the same instant in time from two or more threads.
  3. Calling sqlite3_step() with a sqlite3_stmt* statement pointer that was not obtained from sqlite3_prepare() or sqlite3_prepare16() or that has already been destroyed by sqlite3_finalize().
  4. Trying to bind values to a statement (using sqlite3_bind_...()) while that statement is running.

这是SQLite官网上给出的问题解释。

1.  调用API所用到的指针,第一种情况是没有从sqlite3_open()或者是sqlite3_open16()获得,第二种情况是sqlite3_close()函数已经将数据库关闭了。我是第二种情况。

2.  两个或者更多的线程同时访问该数据库。对于这样的问题,可以通过加上锁进行解决。

3.  sqlite3_step()所用到的变量statement指针,第一种情况是该指针不是从sqlite3_prepare()或者是sqlite3_open16()获得的,第二种情况是该指针已经被销毁或者被释放。这个和1中的情况是一样的,不同的是使用这种指针的函数,两者可以和为一种情况。

4.  试图将values绑定到一个正在运行的statement上。该解释未遇到。(本人遇到:在statement绑定bind值后未reset就又重新对statement绑定bind值)

===================================================================

IOS,SQLite批量插入错误

在数据库中插入数据的时候,报错:Prepare-error library routine called out of sequence

代码如下,麻烦帮我看看错误出在哪儿了。谢谢

NSString *databaseName = @"DB.sqlite";
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];

    sqlite3 *concertsDB;
    const char *dbpath = [databasePath UTF8String];

    if (sqlite3_open(dbpath, &concertsDB) == SQLITE_OK)
    {
        sqlite3_exec(concertsDB, "BEGIN TRANSACTION", 0, 0, 0);
        const char *sqlStatement = "INSERT INTO concertsData VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        sqlite3_stmt *compiledStatement;

        if (sqlite3_prepare_v2(concertsDB, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
            int hasError;

            for (int i=0; i<[events count]; i++) {

                sqlite3_bind_text(compiledStatement, 1, [[[events objectAtIndex:i] title] UTF8String], -1, SQLITE_TRANSIENT);
                sqlite3_bind_int(compiledStatement, 2, [[[events objectAtIndex:i] date] timeIntervalSince1970]);

                sqlite3_bind_text(compiledStatement, 3, [[[events objectAtIndex:i] time] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 4, [[[events objectAtIndex:i] shortDesription] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 5, [[[events objectAtIndex:i] conductor] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 6, [[[events objectAtIndex:i] location] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 7, [[[events objectAtIndex:i] durations] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 8, [[[events objectAtIndex:i] works] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 9, [[[events objectAtIndex:i] solists] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 10, [[[events objectAtIndex:i] fulltext] UTF8String], -1, SQLITE_TRANSIENT);                    

                sqlite3_bind_text(compiledStatement, 11, [[[[events objectAtIndex:i] concertUrl] absoluteString] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 12, [[[[events objectAtIndex:i] buyUrl] absoluteString] UTF8String], -1, SQLITE_TRANSIENT);

                sqlite3_bind_text(compiledStatement, 13, [[[events objectAtIndex:i] imageName] UTF8String], -1, SQLITE_TRANSIENT);

                if (sqlite3_step(compiledStatement) != SQLITE_DONE) {
                    hasError=1;
                    NSLog(@"Prepare-error %s", sqlite3_errmsg(concertsDB));
                }

                sqlite3_clear_bindings(compiledStatement);
            }
            sqlite3_reset(compiledStatement);
            if( hasError == 0 ) {
                sqlite3_exec(concertsDB, "COMMIT", 0, 0, 0);
            }
            else {
                sqlite3_exec(concertsDB, "ROLLBACK", 0, 0, 0);
            }

        }

        sqlite3_close(concertsDB);
    }

SQL Error:library routine called out of sequence.

在Lazarus+ZEOSDBO连接数据库后,进行打开、修改操作SQLite数据库,本机运行正常,可是在测试机上一跑,老是提示“SQL Error:library routine called out...
  • c_huabo
  • c_huabo
  • 2011年11月21日 14:22
  • 5784

library routine called out of sequence

SQLite异常:library routine called out of sequence 最近公司项目中使用sqlite时候出现了library routine called out ...
  • u010226872
  • u010226872
  • 2016年02月14日 10:05
  • 876

解决SQLite异常:library routine called out of sequence

在平常的练习中出现了这样的问题,在网上搜寻了下,
  • u012539899
  • u012539899
  • 2014年07月16日 14:46
  • 3000

Sqlite sqlite3_config 报错 21

要使用Sqlite进行开发,xue
  • Silver_sail
  • Silver_sail
  • 2014年09月04日 09:05
  • 3155

sqlite错误处理:library routine called out of sequence

用c++调sqlite 3.2 api,概率性遇到library routine called out of sequence错误,出现错误后,数据库连接断开,后面的操作都无效。 查了官方的...
  • soberren
  • soberren
  • 2016年07月04日 23:29
  • 214

主题:ORA-01002: fetch out of sequence问题

官方解释: ORA-01002: fetch out of sequence ...
  • annicybc
  • annicybc
  • 2006年05月25日 20:31
  • 14617

ORA-01002 fetch out of sequence

 ORA-01002        fetch out of sequence Cause        In a host language program, a FETCH call...
  • kevin_LCC
  • kevin_LCC
  • 2015年08月13日 15:38
  • 611

异常fetch out of sequence的生成原因

主要是因为使用ExpressDSO.save()(泛指一些需要事务控制,即可提交和回滚支持的方法)时没有将其作为事务提交,在spring.xml里经过以下配置后就可以了          class=...
  • qlampskyface
  • qlampskyface
  • 2005年02月02日 10:23
  • 3661

Error Code: 1414. OUT or INOUT argument 2 for routine company.new_procedure is not a variable or NEW

1、错误描述 16:27:36 call new_procedure(20150112,1) Error Code: 1414. OUT or INOUT argument 2 for routin...
  • you23hai45
  • you23hai45
  • 2015年06月10日 16:30
  • 4944

1414 - OUT or INOUT argument 3 for routine nenghao.xxx is not a variable or NEW pseudo-variable in B

Procedure execution failed 1414 - OUT or INOUT argument 3 for routine nenghao.money_day_all is not ...
  • zb0567
  • zb0567
  • 2017年02月07日 00:49
  • 807
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:解决SQLite异常:library routine called out of sequence
举报原因:
原因补充:

(最多只允许输入30个字)