Answer the question
In order to leave comments, you need to log in
How to write a class to work with sqlite?
I am not selenium in OOP, need help.
There is a class SQLite , it is in the connect() method , it turns out an open sqlite database into the database object.
I would like to implement something like this (so that you can execute queries from other classes without recreating objects of this one) sqlite.query() something like this)
It seems to be called a singleton?
Now I work like this
SQLite sqlite = new SQLite();
sqlite.connect().query();
public class SQLite {
public SqliteDatabase connect()
{
SqliteDatabase database = new SqliteDatabase();
// тут куча кода
database.Open(Application.persistentDataPath + "/db.sqlite");
return database;
}
}
Answer the question
In order to leave comments, you need to log in
I think it's called chaining.
public class SQLite {
private SqliteDatabase link;
private bool isConnected;
public SQLite connect()
{
if (isConnected) return this;
link = new SqliteDatabase();
// тут куча кода
link.Open(Application.persistentDataPath + "/db.sqlite");
isConnected = true;
return this;
}
}
Store your public database wrapper object in some global class and refer to it when needed. Singleton is in behavior and meaning almost the same as a global variable, you don't have to bother.
Especially with SQLite - it doesn't support multithreading, so supporting more than one connection is detrimental in all cases.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question