2011-09-02 69 views
2

嘿,目前我不知道官方如何支持它,但是,有人报告成功使用vici coolStorage与monodroid。 我已经能够将程序集放到我的项目中并进行编译,但是当我尝试使用它们时,某些类会抛出编译时错误。特别是在尝试连接时,例如website.上的monoTouch示例。 使用Vici酷存储与monodroid

 

string dbName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "mydb.db3"); 

// The following line will tell CoolStorage where the database is, 
// create it if it does not exist, and call a delegate which 
// creates the necessary tables (only if the database file was 
// created new) 

CSConfig.SetDB(dbName, true,() => { 
    CSDatabase.ExecuteNonQuery(@"CREATE TABLE person 
           (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, 
            Name TEXT(50) NOT NULL, 
            DateOfBirth TEXT(30) NULL)"); 

}); 
 

我得到尝试使用 CSConfig的方法时,没有智能感知,当我尝试到3个ARGS传递给CSConfig.SetDB()我得到ARGS错误的无效号码。

回答

4

我认为他们的样本是越野车。如果您使用Visual Studio组装浏览器,或MonoDevelop的组装浏览器,甚至只是monop -r:Vici.CoolStorage.MT.dll Vici.CoolStorage.CSConfig,你会看到这些重载SetDB:这些

public static void SetDB (CSDataProvider db); 
public static void SetDB (CSDataProvider db, string contextName); 
public static void SetDB (string dbName); 
public static void SetDB (string dbName, Action creationDelegate); 
public static void SetDB (string dbName, SqliteOption sqliteOption); 
public static void SetDB (string dbName, SqliteOption sqliteOption, Action creationDelegate); 

没有接受bool作为第二个参数,所以我认为他们sample是越野车。

修复的方法是做,因为编译器说,用实际存在过载:

CSConfig.SetDB(dbName,() => { 
    CSDatabase.ExecuteNonQuery(
     @"CREATE TABLE person 
     (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, 
     Name TEXT(50) NOT NULL, 
     DateOfBirth TEXT(30) NULL)"); 
}); 
+0

祝贺并再次感谢。我没有意识到你是那个杰克大声笑 – Terrance

0

好了,所以这里的交易。这个例子是错误的,显然这个项目是开源的。

所以在最新版本。布尔没有超载。 查看源代码片段。

 


using System; 
using System.IO; 
using Mono.Data.Sqlite; 

namespace Vici.CoolStorage 
{ 
    [Flags] 
    public enum SqliteOption 
    { 
     None = 0, 
     CreateIfNotExists = 1, 
     UseConnectionPooling = 2 
    } 

    public static partial class CSConfig 
    { 
     public static void SetDB(string dbName) 
     { 
      SetDB(dbName,SqliteOption.UseConnectionPooling); 
     } 

     public static void SetDB(string dbName, Action creationDelegate) 
     { 
      SetDB(dbName,SqliteOption.UseConnectionPooling|SqliteOption.CreateIfNotExists, creationDelegate); 
     } 

     public static void SetDB(string dbName, SqliteOption sqliteOption) 
     { 
      SetDB(dbName,sqliteOption,null); 
     } 

     public static void SetDB(string dbName, SqliteOption sqliteOption, Action creationDelegate) 
     { 
      bool exists = File.Exists(dbName); 
      bool createIfNotExists = (sqliteOption & SqliteOption.CreateIfNotExists) != 0; 
      bool usePooling = (sqliteOption & SqliteOption.UseConnectionPooling) != 0; 

      if (!exists && createIfNotExists) 
      SqliteConnection.CreateFile(dbName); 

      SetDB(new CSDataProviderSQLite("Data Source=" + dbName + ";Pooling=" + usePooling), DEFAULT_CONTEXTNAME); 

      if (!exists && createIfNotExists && creationDelegate != null) 
       creationDelegate(); 
     } 
    } 
}