Skip to content

Getting Started

子悦解说 edited this page Aug 13, 2025 · 2 revisions

Important

This page simply demonstrates how to use AngelSQLite. If it does not contain the content you need, it is better to read documentation of classes.

Installing the plugin

  1. Downloading AngelSQLite here: https://github.com/ZiYueCommentary/AngelSQLite/releases

  2. Extracting files into your UERM server root directory.

  3. Adding AngelSQLite.as to your scripts in server.cfg.

Connecting the database

SQLiteConnection conn = ConnectSQLite("sqlite.db");

...some logic...

conn.Close();

SQLiteConnection represents a connection with SQLite database, you can use it for many times or just create more connections.

sqlite.db is the path of your database.

Remember to Close() the connection when you finish using it.

Creating a table

SQLiteCommand command = CreateSQLiteCommand("CREATE TABLE players (userid INTEGER default 0 primary key, name TEXT);", conn);
command.ExecuteNonQuery();
command.Finalize();

This creates a table called players, with a primary key userid and a column name. Note that conn is the connection that you have created before. You can use this template to insert rows into your table.

ExecuteNonQuery() executes the command without receiving results.

Remember to Finalize() the command when you finish using it.

Querying data

SQLiteCommand command = CreateSQLiteCommand("SELECT * FROM players;", conn);
SQLiteDataReader reader = command.ExecuteReader();
while(reader.Read())
{
    int userid = reader.GetInt("userid");
    string name = reader.GetText("name");
    print("User ID: " + userid + ", Name: " + name + ");
}
reader.Close();
command.Finalize();

This queries all the users in players table. Note that conn is the connection that you have created before.

ExecuteReader() returns a SQLiteDataReader object for reading the query result. When invoking reader.Read(), it advances the SQLiteDataReader to the next record. It returns true if there are more rows, otherwise false.

reader.GetInt can read an integer column value by column name or index. The same goes for others. Note that the index starts with 1.

Remember to Close() the reader when you finish using it.

Prepared statements

SQLiteCommand comm = CreateSQLiteCommand("INSERT INTO players (userid, name) VALUES (@id, @name);", conn);
comm.BindParameter("@id", 123456);
comm.BindParameter("@name", "EasyT_T");
comm.ExecuteNonQuery();
comm.BindParameter("@id", 789012);
comm.BindParameter("@name", "ZiYueCommentary");
comm.ExecuteNonQuery();
comm.Finalize();

This prepared statement inserts two rows into the players table. Note that conn is the connection that you have created before. The statement is prepared when invoking CreateSQLiteCommand. You can use BindParameter to bind parameters, by column name or index. Note that the index starts with 1.

After executing ExecuteNonQuery(), the parameters of the statement are rested, and ready for bind again. If you are using ExecuteReader(), the parameters will be reset when you invoking reader.Close().

Clone this wiki locally