Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using EsotericSQL;
- namespace ExambleLibrary
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Run your unit tests here.
- //For integration tests, create a .state file.
- //For example: ./automata/test/testmylib.state
- //Write any tests you want to perform there.
- //Next run it through the console.
- //For example: push test testmylib auto
- List<string> QueryOut;
- List<double> QueryOutReal;
- Console.WriteLine("Opening connection");
- SQLTools.OpenFile("test.db", "test");
- Console.WriteLine("CREATE");
- SQLTools.RunNonQuery("test", @"CREATE TABLE IF NOT EXISTS example (
- id INTEGER PRIMARY KEY AUTOINCREMENT,
- decision TEXT,
- value BIGINT
- )");
- Console.WriteLine("INSERT");
- SQLTools.RunNonQuery("test", @"INSERT INTO example (decision, value) VALUES
- ('A', 1),
- ('A', 3),
- ('A', 4),
- ('B', 2),
- ('B', 3),
- ('C', 3)
- ");
- Console.WriteLine("SELECT test 1:");
- QueryOut = SQLTools.RunFullQuery("test", @"SELECT * FROM example");
- foreach (string s in QueryOut) Console.WriteLine(s);
- Console.WriteLine("SELECT test 2:");
- QueryOut = SQLTools.RunFullQuery("test", @"SELECT decision, AVG(value)
- FROM example
- GROUP BY decision
- ORDER BY AVG(value) DESC
- ");
- foreach (string s in QueryOut) Console.WriteLine(s);
- Console.WriteLine("SELECT test 3:");
- QueryOutReal = SQLTools.RunRealQuery("test", @"SELECT AVG(value)
- FROM example
- GROUP BY decision
- ORDER BY AVG(value) DESC
- ");
- foreach (double d in QueryOutReal) Console.WriteLine(d);
- Console.WriteLine("Closing connection");
- SQLTools.CloseFile("test");
- Console.WriteLine("Removing test file");
- SQLTools.DeleteFile("test.db");
- Console.ReadKey();
- }
- }
- public class EsotericModule
- {
- //Delegate types used for binding code from the engine.
- //Don't change these.
- public delegate bool GetLogicDelegate(ulong CallID);
- public delegate long GetIntegerDelegate(ulong CallID);
- public delegate double GetRealDelegate(ulong CallID);
- public delegate string GetStringDelegate(ulong CallID);
- public delegate List<bool> GetLogicArrayDelegate(ulong CallID);
- public delegate List<long> GetIntegerArrayDelegate(ulong CallID);
- public delegate List<double> GetRealArrayDelegate(ulong CallID);
- public delegate List<string> GetStringArrayDelegate(ulong CallID);
- public delegate bool CallLogicDelegate(ulong CallID, string Code);
- public delegate long CallIntegerDelegate(ulong CallID, string Code);
- public delegate double CallRealDelegate(ulong CallID, string Code);
- public delegate string CallStringDelegate(ulong CallID, string Code);
- public delegate List<bool> CallLogicArrayDelegate(ulong CallID, string Code);
- public delegate List<long> CallIntegerArrayDelegate(ulong CallID, string Code);
- public delegate List<double> CallRealArrayDelegate(ulong CallID, string Code);
- public delegate List<string> CallStringArrayDelegate(ulong CallID, string Code);
- public delegate void CallVoidDelegate(ulong CallID, string Code);
- //This function defines the name of your library.
- //This name will be used to call the library from the engine.
- //For example: lib "esql" "open" "test.db" "test"
- // lib "esql" "close" "test"
- // etc.
- public string GetName(ulong CallID) => "esql";
- //These functions are called when the engine tries to access the library.
- //The function depends on the return type requested.
- public bool GetLogic(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunLogicQuery(TakeStringParam(CallID), TakeStringParam(CallID))[0];
- default: throw new NotImplementedException();
- }
- }
- public long GetInteger(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunIntegerQuery(TakeStringParam(CallID), TakeStringParam(CallID))[0];
- default: throw new NotImplementedException();
- }
- }
- public double GetReal(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunRealQuery(TakeStringParam(CallID), TakeStringParam(CallID))[0];
- default: throw new NotImplementedException();
- }
- }
- public string GetString(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunFullQuery(TakeStringParam(CallID), TakeStringParam(CallID))[0];
- default: throw new NotImplementedException();
- }
- }
- public List<bool> GetLogicArray(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunLogicQuery(TakeStringParam(CallID), TakeStringParam(CallID));
- default: throw new NotImplementedException();
- }
- }
- public List<long> GetIntegerArray(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunIntegerQuery(TakeStringParam(CallID), TakeStringParam(CallID));
- default: throw new NotImplementedException();
- }
- }
- public List<double> GetRealArray(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunRealQuery(TakeStringParam(CallID), TakeStringParam(CallID));
- default: throw new NotImplementedException();
- }
- }
- public List<string> GetStringArray(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "run": return SQLTools.RunFullQuery(TakeStringParam(CallID), TakeStringParam(CallID));
- default: throw new NotImplementedException();
- }
- }
- //This function represents void calls.
- //Note the use of Take*Param(CallID) calls to obtain parameters.
- public void GetVoid(ulong CallID)
- {
- switch (TakeStringParam(CallID))
- {
- case "open":
- SQLTools.OpenFile(TakeStringParam(CallID), TakeStringParam(CallID));
- break;
- case "close":
- SQLTools.CloseFile(TakeStringParam(CallID));
- break;
- case "delete":
- SQLTools.DeleteFile(TakeStringParam(CallID));
- break;
- case "run":
- SQLTools.RunNonQuery(TakeStringParam(CallID), TakeStringParam(CallID));
- break;
- default: throw new NotImplementedException();
- }
- }
- //Use these properties to get parameters for your library call.
- //Select the property based on the return value you want.
- //Pass your CallID token into the first parameter.
- public GetLogicDelegate TakeLogicParam { get; set; }
- public GetIntegerDelegate TakeIntegerParam { get; set; }
- public GetRealDelegate TakeRealParam { get; set; }
- public GetStringDelegate TakeStringParam { get; set; }
- public GetLogicArrayDelegate TakeLogicArrayParam { get; set; }
- public GetIntegerArrayDelegate TakeIntegerArrayParam { get; set; }
- public GetRealArrayDelegate TakeRealArrayParam { get; set; }
- public GetStringArrayDelegate TakeStringArrayParam { get; set; }
- //Use these properties to call code inside of the engine.
- //Select the property based on the return value you want.
- //Pass your CallID token into the first parameter and a valid script statement into the second.
- public CallLogicDelegate CallLogicCode { get; set; }
- public CallIntegerDelegate CallIntegerCode { get; set; }
- public CallRealDelegate CallRealCode { get; set; }
- public CallStringDelegate CallStringCode { get; set; }
- public CallLogicArrayDelegate CallLogicArrayCode { get; set; }
- public CallIntegerArrayDelegate CallIntegerArrayCode { get; set; }
- public CallRealArrayDelegate CallRealArrayCode { get; set; }
- public CallStringArrayDelegate CallStringArrayCode { get; set; }
- public CallVoidDelegate CallVoidCode { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment