mysql,sqlite哪个好

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql,sqlite哪个好相关的知识,希望对你有一定的参考价值。

mysql,sqlite各自优势。

参考技术A 1、使用广度:mysql>sqlite。导致网络上mysql相关的页面更多
2、软硬环境:mysql>sqlite。mysql比较健壮,适合于各种软硬件下的各种环境,能够依据硬件及配置发挥不同的性能,sqlite却比较单一。
3、查询语法:mysql>sqlite。mysql的sql语法结构比较健全,sqlite稍逊色
4、适用场合:mysql 中大型网络项目,sqlite小型网络项目或中小型软件项目
5、维护难度:mysql>sqlite。mysql具备各种维护方式和辅助软件,sqllite维护方式较少
6、性能评分:分别在不同的配置上,执行各种同功能的sql语句,会有不同的性能体现,这个无法评比。只能依据自己的需要来选择最合适的。本回答被提问者采纳

MySQL

http://www.runoob.com/sqlite/sqlite-expressions.html

 

封装好的sql

using UnityEngine;

using System;
using System.Collections;
using Mono.Data.Sqlite;


public class DbAccess

{


private SqliteConnection dbConnection;

private SqliteCommand dbCommand;

private SqliteDataReader reader;


public DbAccess (string connectionString)

{

OpenDB (connectionString);

}
public DbAccess ()
{

}

public void OpenDB (string connectionString)

{
try
{
dbConnection = new SqliteConnection (connectionString);

dbConnection.Open ();

Debug.Log ("Connected to db");
}
catch(Exception e)
{
string temp1 = e.ToString();
Debug.Log(temp1);
}

}

 

public void CloseSqlConnection ()

{

if (dbCommand != null) {

dbCommand.Dispose ();

}

dbCommand = null;

if (reader != null) {

reader.Dispose ();

}

reader = null;

if (dbConnection != null) {

dbConnection.Close ();

}

dbConnection = null;

Debug.Log ("Disconnected from db.");

}


public SqliteDataReader ExecuteQuery (string sqlQuery)

{

dbCommand = dbConnection.CreateCommand ();

dbCommand.CommandText = sqlQuery;

 

reader = dbCommand.ExecuteReader ();

 

 

return reader;

}


public SqliteDataReader ReadFullTable (string tableName)

{

string query = "SELECT * FROM " + tableName;

return ExecuteQuery (query);

}

 

public SqliteDataReader InsertInto (string tableName, string[] values)

{

string query = "INSERT INTO " + tableName + " VALUES (" + values[0];

for (int i = 1; i < values.Length; ++i) {

query += ", " + values[i];

}

query += ")";

return ExecuteQuery (query);

}


public SqliteDataReader UpdateInto (string tableName, string []cols,string []colsvalues,string selectkey,string selectvalue)
{


string query = "UPDATE "+tableName+" SET "+cols[0]+" = "+colsvalues[0];

for (int i = 1; i < colsvalues.Length; ++i) {

query += ", " +cols[i]+" ="+ colsvalues[i];
}

query += " WHERE "+selectkey+" = "+selectvalue+" ";

return ExecuteQuery (query);
}


public SqliteDataReader Delete(string tableName,string []cols,string []colsvalues)
{
string query = "DELETE FROM "+tableName + " WHERE " +cols[0] +" = " + colsvalues[0];

for (int i = 1; i < colsvalues.Length; ++i) {

query += " or " +cols[i]+" = "+ colsvalues[i];
}
return ExecuteQuery (query);
}


public SqliteDataReader InsertIntoSpecific (string tableName, string[] cols, string[] values)

{

if (cols.Length != values.Length) {

throw new SqliteException ("columns.Length != values.Length");

}

string query = "INSERT INTO " + tableName + "(" + cols[0];

for (int i = 1; i < cols.Length; ++i) {

query += ", " + cols[i];

}

query += ") VALUES (" + values[0];

for (int i = 1; i < values.Length; ++i) {

query += ", " + values[i];

}

query += ")";

return ExecuteQuery (query);

}

 

public SqliteDataReader DeleteContents (string tableName)

{

string query = "DELETE FROM " + tableName;

return ExecuteQuery (query);

}


public SqliteDataReader CreateTable (string name, string[] col, string[] colType)

{

if (col.Length != colType.Length) {

throw new SqliteException ("columns.Length != colType.Length");

}

string query = "CREATE TABLE " + name + " (" + col[0] + " " + colType[0];

for (int i = 1; i < col.Length; ++i) {

query += ", " + col[i] + " " + colType[i];

}

query += ")";


return ExecuteQuery (query);

}




public SqliteDataReader SelectWhere (string tableName, string[] items, string[] col, string[] operation, string[] values)

{

if (col.Length != operation.Length || operation.Length != values.Length) {

throw new SqliteException ("col.Length != operation.Length != values.Length");

}

string query = "SELECT " + items[0];

for (int i = 1; i < items.Length; ++i) {

query += ", " + items[i];

}

query += " FROM " + tableName + " WHERE " + col[0] + operation[0] + "‘" + values[0] + "‘ ";

for (int i = 1; i < col.Length; ++i) {

query += " AND " + col[i] + operation[i] + "‘" + values[0] + "‘ ";

}


return ExecuteQuery (query);

 

}

 

 

 

}

 

 

 

一般调用

 

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

 

public class ZYSQLTest : MonoBehaviour {

 

//创建表
void CreateMyCul()
{
string appDBPath = Application.persistentDataPath + "/zhongyingying.db";

if (!File.Exists(appDBPath))
{

 

DbAccess db = new DbAccess("URI=file:" + appDBPath);
db.CreateTable("zy", new string[] { "name", "age", "rank" }, new string[] { "text", "text", "text" });

Debug.Log("CreateSuccessful!创建表成功!");
db.CloseSqlConnection();

 

}

else
{
Debug.Log("File Exists!已经存在了!");
}

 

}
//插入数据
void InsertMyData()
{
string appDBPath = Application.persistentDataPath + "/zhongyingying.db";

DbAccess db = new DbAccess("URI=file:" + appDBPath);
Debug.Log(db);
db.InsertInto("zy", new string[] { "‘missZhong‘", "‘24‘", "‘1‘" });
db.InsertInto("zy", new string[] { "‘MrZhang‘", "‘22‘", "‘5‘" });

 

db.CloseSqlConnection();
Debug.Log("InsertInfoSuccessful!!!插入值成功!");

 

}
//删除数据
void DeleteMySelectedData()
{
string appDBPath = Application.persistentDataPath + "/zhongyingying.db";
DbAccess db = new DbAccess("URI=file:" + appDBPath);
db.Delete("zy", new string[] { "‘age‘" }, new string[] { "‘24‘" });
db.CloseSqlConnection();
Debug.Log("deleteSuccessful!删除成功!");
}
//查询数据
void SelectMyData()
{
string appDBPath = Application.persistentDataPath + "/zhongyingying.db";
DbAccess db = new DbAccess("URI=file:" + appDBPath);
SqliteDataReader sdr = db.SelectWhere("zy", new string[] { "age", "rank" }, new string[] { "age" }, new string[] { "=" }, new string[] { "24" });
db.CloseSqlConnection();
Debug.Log("SelectSuccessful!查询成功!");
Debug.Log("查询到的数据是______"+db);

 


}
//数据展示
void OnGUI()
{
if (GUI.Button(new Rect(350, 50, 100, 100), "创建表"))
{
CreateMyCul();
}
if (GUI.Button(new Rect(350, 200, 100, 100), "插入数据"))
{
InsertMyData();
}
if (GUI.Button(new Rect(350, 350, 100, 100), "删除数据"))
{
DeleteMySelectedData();
}
if (GUI.Button(new Rect(350, 500, 100, 100), "查询数据"))
{
SelectMyData();
}
}
}

 

以上是关于mysql,sqlite哪个好的主要内容,如果未能解决你的问题,请参考以下文章

sqlite 怎么知道索引在哪个索引btree里

Sqlite 还是 MySql?如何决定? [关闭]

SQL 和 SQLite 的有啥分别? 重视哪个会好点?

是否有与 MySQL 的 DESCRIBE [表] 等效的 SQLite?

Django:用于开发的 sqlite,用于生产的 mysql? [关闭]

如何在 Rails 中将我的数据库从 SQLite 更改为 MYSQL