2
votes

I try to compile my game on Unity, using SQLite as my database. But on the console this error message appears:

error CS0433: Type 'IDataReader' exists in 'System.Data, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = b77a5c561934e089' and 'Netstandard, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = cc7b13ffcd2ddd51'

How can I solve this?

follow my code below

PS: sorry for the bad English I am using google translator

// Use this for initialization
void Start () {

}

public void OpenDB(string p)
{
    Debug.Log("Call to OpenDB:" + p);
    // check if file exists in Application.persistentDataPath
    string filepath = Application.persistentDataPath + "/" + p;
    if(!File.Exists(filepath))
    {
        Debug.LogWarning("File \"" + filepath + "\" does not exist. Attempting to create from \"" +
                         Application.dataPath + "!/assets/" + p);
        // if it doesn't ->
        // open StreamingAssets directory and load the db -> 
        WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + p);
        while(!loadDB.isDone) {}
        // then save to Application.persistentDataPath
        File.WriteAllBytes(filepath, loadDB.bytes);
    }

    //open db connection
    connection = "URI=file:" + filepath;
    Debug.Log("Stablishing connection to: " + connection);
    dbcon = new SqliteConnection(connection);
    dbcon.Open();
}

public void CloseDB(){
    reader.Close(); // clean everything up
    reader = null;
    dbcmd.Dispose();
    dbcmd = null;
    dbcon.Close();
    dbcon = null;
}

public IDataReader BasicQuery(string query){ // run a basic Sqlite query
    dbcmd = dbcon.CreateCommand(); // create empty command
    dbcmd.CommandText = query; // fill the command
    reader = dbcmd.ExecuteReader(); // execute command which returns a reader
    return reader; // return the reader

}


public bool CreateTable(string name,string[] col, string[] colType){ // Create a table, name, column array, column type array
    string query;
    query  = "CREATE TABLE " + name + "(" + col[0] + " " + colType[0];
    for(var i=1; i< col.Length; i++){
        query += ", " + col[i] + " " + colType[i];
    }
    query += ")";
    try{
        dbcmd = dbcon.CreateCommand(); // create empty command
        dbcmd.CommandText = query; // fill the command
        reader = dbcmd.ExecuteReader(); // execute command which returns a reader
    }
    catch(Exception e){

        Debug.Log(e);
        return false;
    }
    return true;
}

public int InsertIntoSingle(string tableName, string colName , string value ){ // single insert
    string query;
    query = "INSERT INTO " + tableName + "(" + colName + ") " + "VALUES (" + value + ")";
    try
    {
        dbcmd = dbcon.CreateCommand(); // create empty command
        dbcmd.CommandText = query; // fill the command
        reader = dbcmd.ExecuteReader(); // execute command which returns a reader
    }
    catch(Exception e){

        Debug.Log(e);
        return 0;
    }
    return 1;
}

public int InsertIntoSpecific(string tableName, string[] col, string[] values){ // Specific insert with col and values
    string query;
    query = "INSERT INTO " + tableName + "(" + col[0];
    for(int i=1; i< col.Length; i++){
        query += ", " + col[i];
    }
    query += ") VALUES (" + values[0];
    for(int i=1; i< col.Length; i++){
        query += ", " + values[i];
    }
    query += ")";
    Debug.Log(query);
    try
    {
        dbcmd = dbcon.CreateCommand();
        dbcmd.CommandText = query;
        reader = dbcmd.ExecuteReader();
    }
    catch(Exception e){

        Debug.Log(e);
        return 0;
    }
    return 1;
}

public int InsertInto(string tableName /*, string[] values*/ ){ // basic Insert with just values
    string query;
    //  query = "INSERT INTO " + tableName + " VALUES (" + values[0];
    //  for(int i=1; i< values.Length; i++){
    //      query += ", " + values[i];
    //  }
    //  query += ")";
    query = "INSERT into" + tableName + "VALUES (1,'vini','aa',0)";

    try
    {
        dbcmd = dbcon.CreateCommand();
        dbcmd.CommandText = query;
        reader = dbcmd.ExecuteReader();
    }
    catch(Exception e){

        Debug.Log(e);
        return 0;
    }
    return 1;
}

public ArrayList SingleSelectWhere(string tableName , string itemToSelect,string wCol,string wPar, string wValue){ // Selects a single Item
    string query;
    query = "SELECT " + itemToSelect + " FROM " + tableName + " WHERE " + wCol + wPar + wValue; 
    dbcmd = dbcon.CreateCommand();
    dbcmd.CommandText = query;
    reader = dbcmd.ExecuteReader();
    //string[,] readArray = new string[reader, reader.FieldCount];
    string[] row = new string[reader.FieldCount];
    ArrayList readArray = new ArrayList();
    while(reader.Read()){
        int j=0;
        while(j < reader.FieldCount)
        {
            row[j] = reader.GetString(j);
            j++;
        }
        readArray.Add(row);
    }
    return readArray; // return matches
}

// Update is called once per frame
void Update () {

}

}

1

1 Answers

1
votes

you named IDataReader as a your method however it is already part of System.Data's interface. You can check more information about IDataReader from microsoft site

https://docs.microsoft.com/tr-tr/dotnet/api/system.data.idatareader?view=netframework-4.8

for your problem you just change the name of IDataReader to anything else.