本文介绍了如何使用(创建数据库,创建表,查询等)praeclarum源码网?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用此连结提供的sqlite-net 。



不幸的是,入门文档还不够。它甚至没有提到如何创建数据库。我试着看看例子,不幸的是,例子是破碎的(无法编译,运行时错误等)。



我可以在网上找到的最实用的教程是



不幸的是,sqlite-net不能完全支持sqlite.org sqlite实现,因此使得教程对praeclarum sqlite-net无用。



在教程中做同样的事情,但在praeclarum sqlite-net中的等效方法是什么?



/ p>

创建数据库(这里是我卡住的地方)

  SQLiteConnection.CreateFile (MyDatabase.sqlite); 

连接数据库

  SQLiteConnection m_dbConnection; 
m_dbConnection = new SQLiteConnection(Data Source = MyDatabase.sqlite; Version = 3;);
m_dbConnection.Open();

创建表格

  string sql =create table highscores(name varchar(20),score int); 
SQLiteCommand command = new SQLiteCommand(sql,m_dbConnection);
command.ExecuteNonQuery();

填充表

 code> string sql =insert into highscores(name,score)values('Me',3000); 
SQLiteCommand command = new SQLiteCommand(sql,m_dbConnection);
command.ExecuteNonQuery();
sql =insert into highscores(name,score)values('Myself',6000);
command = new SQLiteCommand(sql,m_dbConnection);
command.ExecuteNonQuery();
sql =insert into highscores(name,score)values('And I',9001);
command = new SQLiteCommand(sql,m_dbConnection);
command.ExecuteNonQuery();

查询数据库

 code> string sql =select * from highscores order by score desc; 
SQLiteCommand command = new SQLiteCommand(sql,m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while(reader.Read())
Console.WriteLine(Name:+ reader [name] +\tScore:+ reader [score]);


解决方案

在您可以使用lambdas的位置。这些类是强类型的。



使事情更清晰。



如果你进入任何数量的数据缓存,你最终会希望你有像Microsoft的同步框架在Mono中使用。我真的猜你的帖子,你正在看着使用Xamarin。看看他们的SQLCipher组件,如果你要本地缓存数据。



此外,如果你使用SQLCipher通过组件存储..它在Android 2.3起。所以不要指望一个完全向后兼容的系统,即使支持库添加到您的项目。



var db = new SQLiteConnection(sqllite.db)



db.CreateTable< SyncRecord> (SyncRecord(){SyncDate = DateTime.UtcNow});

code>



var query = db.Table< SyncRecord> ().Where(/ *你的lambda过滤* /);


I want to use sqlite-net available from this link https://github.com/praeclarum/sqlite-net.

Unfortunately, the getting started documentation are not enough. It doesnt even mention how to create a database. I tried looking at the examples, unfortunately, the examples are broken(unable to compile, run time error etc).

The most practical tutorial i can find on the net is http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/

Unfortunately, sqlite-net doesnt fully support sqlite.org sqlite implementation, thus making the tutorial useless for praeclarum sqlite-net.

What is the equivalent method to do the same thing from the tutorial but in praeclarum sqlite-net?

From the tutorial

Create database(Here is where i stuck)

SQLiteConnection.CreateFile("MyDatabase.sqlite");

Connect to database

SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();

Create table

string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();

Fill table

string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();

Query database

string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
    Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
解决方案

In your Where you can use lambdas. The classes are strongly typed.

Makes things a lot cleaner.

If you get into any amount of data caching, you'll end up wishing you had something like Microsoft's sync framework to use in Mono. I'm really guessing by your post, that you are looking at using Xamarin. Take a look at their SQLCipher component, if you are going to be caching data locally.

Also, if you do use SQLCipher via the component store.. it works in Android 2.3 on up. So don't expect a fully backward compatible system even with the Support Library added to your project.

var db = new SQLiteConnection("sqllite.db")

db.CreateTable<SyncRecord> ();

db.Insert (new SyncRecord () { SyncDate = DateTime.UtcNow });

var query = db.Table<SyncRecord> ().Where( /* your lambda to filter*/);

这篇关于如何使用(创建数据库,创建表,查询等)praeclarum源码网?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 12:53