Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Data;
- using Mono.Data.Sqlite;
- using UnityEngine;
- public class DBWrapper {
- private static SqliteConnection conn = null;
- private static SqliteCommand readCmd = null;
- private static string DBPath() {
- return "URI=file:Assets/Resources/database.sqlite";
- }
- private static void MakeHandle() {
- if (conn == null) {
- conn = new SqliteConnection(DBPath());
- conn.Open();
- }
- }
- public static SqliteDataReader Query(string query, List<SqliteParameter> queryParams) {
- MakeHandle();
- if (DBWrapper.readCmd == null) {
- DBWrapper.readCmd = conn.CreateCommand();
- }
- readCmd.CommandType = CommandType.Text;
- readCmd.CommandText = query;
- if (queryParams != null) {
- foreach (var qp in queryParams) {
- readCmd.Parameters.Add(qp);
- }
- }
- return readCmd.ExecuteReader();
- }
- }
- ...
- using (var reader = DBWrapper.Query("SELECT * FROM Ships;", null)) {
- Debug.Log("Query time");
- while (reader.Read()) {
- var fields = new object[reader.FieldCount];
- Debug.Log("Got read line " + string.Join(",", fields));
- var ship = new ShipAsset(reader);
- ships[ship.dbName] = ship;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement