Search Unity

Unity and SQLite....

Discussion in 'Scripting' started by alienx2, Apr 4, 2011.

  1. alienx2

    alienx2

    Joined:
    Nov 19, 2010
    Posts:
    40
    Hi...well I don't understand what mean this error. and im really new to C#...


    Code (csharp):
    1. VerificationException: Error verifying Mono.Data.Sqlite.SqliteConvert:UTF8ToString (intptr): Incompatible parameter value with constructor signature: sbyte* X void* (Native Pointer) at 0x0032
    2. Mono.Data.Sqlite.SqliteConvert.ToString (IntPtr nativestring)
    3. Mono.Data.Sqlite.Sqlite3.SqliteLastError ()
    4. Mono.Data.Sqlite.Sqlite3.Prepare (System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, System.String strRemain)
    5. Mono.Data.Sqlite.SqliteCommand.BuildNextCommand ()

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using Mono.Data.Sqlite;
    4. using System;
    5. using System.Data;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8.  
    9. public class SQLiteServer : MonoBehaviour {
    10.  
    11.     private static IDbConnection dbcmd;
    12.  
    13.     // Use this for initialization
    14.     void Start () {
    15.         string id = "1";
    16.        
    17.         string connectionString = "URI=file:/Users/[User]/test.db";
    18.                    
    19.         IDbConnection conn = new SqliteConnection(connectionString);
    20.          
    21.         conn.Open();
    22.          
    23.         print("Connection: " + conn.State);
    24.        
    25.         IDbCommand dbcmd = conn.CreateCommand();
    26.        
    27.         dbcmd.CommandText = "SELECT * FROM TestTable WHERE id=" + id;
    28.        
    29.         IDataReader reader = dbcmd.ExecuteReader();
    30.        
    31.         while(reader.Read())
    32.         {
    33.             id = reader["id"].ToString();
    34.             string CreatedDate = reader["CreatedDate"].ToString();
    35.             string Active = reader["Active"].ToString();
    36.             string Name = reader["Name"].ToString();
    37.             print(id + " " + CreatedDate + " " + Active + " " + Name);
    38.         }
    39.        
    40.         reader.Close();
    41.         reader.Dispose();
    42.         conn.Close();
    43.         conn.Dispose();
    44.     }
    45. }
     
  2. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    564
    I don't know about the error, but have you tried using "reader.GetString()" instead of "ToString()"?

    Jeff
     
  3. alienx2

    alienx2

    Joined:
    Nov 19, 2010
    Posts:
    40

    Yep..still same error... i tried put "print ("ENTER");" before the line "string connectionString = "URI=file:/Users/[User]/test.db";" it has show up in console then next doesnt show up "Connection: Open" from the code: Print("Connection: " + conn.State);...

    I wonder something wrong with connection string...
     
  4. andorov

    andorov

    Joined:
    Feb 10, 2011
    Posts:
    1,061
    Is perhaps the data in the database NOT in UTF8?
     
  5. alienx2

    alienx2

    Joined:
    Nov 19, 2010
    Posts:
    40
    I found the problem... it was DLL not compatible or broken DLL.. so i found other DLL was working and can connect and even also works with export... :)
    Thanks Jgodfrey and Andorov ^_^