166 lines
6.5 KiB
C#
166 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using DynamORM;
|
|
using DynamORM.Helpers;
|
|
using DynamORM.Mapper;
|
|
using Tester.RealTests;
|
|
|
|
namespace Tester
|
|
{
|
|
internal class Program
|
|
{
|
|
private static DynamicDatabase GetORM()
|
|
{
|
|
return new DynamicDatabase(System.Data.SqlClient.SqlClientFactory.Instance,
|
|
//"packet size=4096;User Id=sa;Password=sWe7PepR;data source=192.168.22.10;initial catalog=PLAYGROUND;",
|
|
"packet size=4096;User Id=sa;Password=sWe7PepR;data source=192.168.22.10;initial catalog=MOM_DEMO_WMS_FILLED;",
|
|
DynamicDatabaseOptions.SingleConnection | DynamicDatabaseOptions.SingleTransaction | DynamicDatabaseOptions.SupportSchema |
|
|
DynamicDatabaseOptions.SupportStoredProcedures | DynamicDatabaseOptions.SupportTop | DynamicDatabaseOptions.DumpCommands);
|
|
|
|
////return new DynamORM.DynamicDatabase(System.Data.SQLite.SQLiteFactory.Instance,
|
|
//// "Data Source=test.db3;",
|
|
//// DynamORM.DynamicDatabaseOptions.SingleConnection | DynamORM.DynamicDatabaseOptions.SingleTransaction |
|
|
//// DynamORM.DynamicDatabaseOptions.SupportSchema | DynamORM.DynamicDatabaseOptions.SupportLimitOffset);
|
|
///
|
|
}
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
|
|
using (var db = GetORM())
|
|
{
|
|
//ProcedureHell(db);
|
|
OddNullabeleProblem.Test(db);
|
|
|
|
TableFun(db);
|
|
}
|
|
}
|
|
|
|
private static void TableFun(DynamicDatabase db)
|
|
{
|
|
try
|
|
{
|
|
db.Execute("DROP TABLE Experiments ");
|
|
}
|
|
catch { }
|
|
|
|
db.Execute(@"CREATE TABLE Experiments (
|
|
id int NOT NULL PRIMARY KEY,
|
|
t1 nvarchar(50) NOT NULL DEFAULT N'',
|
|
t2 varchar(50) NOT NULL DEFAULT '',
|
|
dd date,
|
|
tt time);");
|
|
|
|
db.Insert<Ex>().Insert(new Ex
|
|
{
|
|
id = 1,
|
|
t1 = "T1",
|
|
t2 = "T1",
|
|
dd = DateTime.Now,
|
|
tt = TimeSpan.FromDays(2) + TimeSpan.FromHours(10),
|
|
}).Execute();
|
|
|
|
var tt = db.From<Ex>().Where(x => x.id == 1).ToList<Ex>().FirstOrDefault();
|
|
|
|
db.Update<Ex>().Where(x => x.id == 1).Set(x => x.tt = TimeSpan.FromMinutes(10), x => x.dd = DateTime.Now.AddDays(2)).Execute();
|
|
|
|
db.Execute("DROP TABLE Experiments ");
|
|
}
|
|
|
|
[Table(Name = "Experiments")]
|
|
private class Ex
|
|
{
|
|
public int id { get; set; }
|
|
public string t1 { get; set; }
|
|
public string t2 { get; set; }
|
|
public DateTime dd { get; set; }
|
|
public TimeSpan tt { get; set; }
|
|
}
|
|
|
|
private static void ProcedureHell(DynamicDatabase db)
|
|
{
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_Scalar AS SELECT 42;");
|
|
var res0 = db.Procedures.sp_Exp_Scalar();
|
|
var res1 = db.Procedures.sp_Exp_Scalar<int>();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_ReturnInt AS RETURN 42;");
|
|
var res2 = db.Procedures.sp_Exp_ReturnInt();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeData AS
|
|
SELECT 1 Id, 'Some Name 1' [Name], 'Some Desc 1' [Desc], GETDATE() [Date]
|
|
UNION ALL SELECT 2 Id, 'Some Name 2', 'Some Desc 2', GETDATE() [Date];");
|
|
var res3 = db.Procedures.sp_Exp_SomeData<sp_Exp_SomeData_Result>();
|
|
var res4 = db.Procedures.sp_Exp_SomeData<List<sp_Exp_SomeData_Result>>();
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeInputAndOutput
|
|
@Name nvarchar(50),
|
|
@Result nvarchar(256) OUTPUT
|
|
AS
|
|
SELECT @Result = 'Hi, ' + @Name + ' your lucky number is 42!';");
|
|
var res5 = db.Procedures.sp_Exp_SomeInputAndOutput<string, sp_Exp_SomeInputAndOutput_Result>(Name: "G4g4r1n", out_Result: new DynamicColumn
|
|
{
|
|
Schema = new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
},
|
|
}, ret_Return: 0);
|
|
var res6 = db.Procedures.sp_Exp_SomeInputAndOutput<string, sp_Exp_SomeInputAndOutput_Result>(Name: "G4g4r1n", out_Result: new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
}, ret_Return: 0);
|
|
|
|
db.Execute(@"CREATE OR ALTER PROCEDURE sp_Exp_SomeInputAndOutputWithDataAndReturn
|
|
@Name nvarchar(50),
|
|
@Result nvarchar(256) OUTPUT
|
|
AS
|
|
SELECT @Result = 'Hi, ' + @Name + ' your lucky number is 42!'
|
|
|
|
SELECT 1 Id, 'Some Name 1' [Name], 'Some Desc 1' [Desc], GETDATE() [Date]
|
|
UNION ALL SELECT 2 Id, 'Some Name 2', 'Some Desc 2', GETDATE() [Date]
|
|
|
|
RETURN 42;");
|
|
var res7 = db.Procedures.sp_Exp_SomeInputAndOutputWithDataAndReturn<List<sp_Exp_SomeInputAndOutputWithDataAndReturn_Result.Data>, sp_Exp_SomeInputAndOutputWithDataAndReturn_Result>(Name: "G4g4r1n", out_Result: new DynamicColumn
|
|
{
|
|
Schema = new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
},
|
|
}, ret_Return: 0);
|
|
var res8 = db.Procedures.sp_Exp_SomeInputAndOutputWithDataAndReturn<List<sp_Exp_SomeInputAndOutputWithDataAndReturn_Result.Data>, sp_Exp_SomeInputAndOutputWithDataAndReturn_Result>(Name: "G4g4r1n", out_Result: new DynamicSchemaColumn
|
|
{
|
|
Size = 256,
|
|
}, ret_Return: 0);
|
|
}
|
|
|
|
private class sp_Exp_SomeData_Result
|
|
{
|
|
public virtual int Id { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual string Desc { get; set; }
|
|
public virtual DateTime Date { get; set; }
|
|
}
|
|
|
|
private class sp_Exp_SomeInputAndOutput_Result
|
|
{
|
|
public virtual string Result { get; set; }
|
|
public virtual string Return { get; set; }
|
|
}
|
|
|
|
private class sp_Exp_SomeInputAndOutputWithDataAndReturn_Result
|
|
{
|
|
public class Data
|
|
{
|
|
public virtual int Id { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual string Desc { get; set; }
|
|
public virtual DateTime Date { get; set; }
|
|
}
|
|
|
|
public virtual List<Data> sp_Exp_SomeInputAndOutputWithDataAndReturn { get; set; }
|
|
public virtual string Result { get; set; }
|
|
public virtual string Return { get; set; }
|
|
}
|
|
}
|
|
} |