Ejemplo n.º 1
0
        public void SqlCallsWrapper()
        {
            var code     = @"
require data
class a prototype=dbtable 
    void X 'Bla-bla' cs-wrap=scalar cs-return=long
        @id=long : (
            SELECT 1;
        )
    void Y 'Ta-da' cs-wrap=multiplereader 
        @id=long : (
            SELECT 1;
            SELECT 2;
        )";
            var model    = PersistentModel.Compile(code);
            var table    = model["a"];
            var function = table.GetObject <SqlFunction>("X");

            Assert.NotNull(function);
            var writer = new PokoObjectCacheWriter(table)
            {
                DoWriteClassWrapper   = false,
                DoWriteModelLink      = false,
                DoWriteSqlMethods     = false,
                DoWriteTableQuery     = false,
                DoWriteObjectWrappers = true
            };
            var result = writer.ToString();

            Console.WriteLine(result);
            var simpleResult = Regex.Replace(result, @"\s", "").Replace("\"", "'");

            Assert.AreEqual(simpleResult, Regex.Replace(@"		private DbCommandWrapper _XWrapper = new DbCommandWrapper{ObjectName='dbo.aX',Notation=DbCallNotation.Scalar};
		///<summary>Bla-bla</summary>
		public Int64 XGeneric (object parameters) {
			var command = _XWrapper.Clone(parameters,GetConnection());
			var result = DbCommandExecutor.Default.GetResultSync(command);
			var convertedResult = result.To<Int64>();
			return convertedResult;
		}
		///<summary>Bla-bla</summary>
		public Int64 X (Int64 id = default(Int64)){
			return XGeneric (new{id});
		}
		private DbCommandWrapper _YWrapper = new DbCommandWrapper{ObjectName='dbo.aY',Notation=DbCallNotation.MultipleReader};
		///<summary>Ta-da</summary>
		public object YGeneric (object parameters) {
			var command = _YWrapper.Clone(parameters,GetConnection());
			var result = DbCommandExecutor.Default.GetResultSync(command);
			return result;
		}
		///<summary>Ta-da</summary>
		public object Y (Int64 id = default(Int64)){
			return YGeneric (new{id});
		}"        , @"\s", ""));
        }
Ejemplo n.º 2
0
        public void AdapterGotGeneratedSqlMethod()
        {
            var model    = PersistentModel.Compile(SimplestTableFunction);
            var b        = model["B"];
            var adaptgen = new PokoObjectCacheWriter(b);
            var code     = adaptgen.ToString();

            Console.WriteLine(code);
            Console.WriteLine(code.Replace("\"", "\"\""));
            Assert.AreEqual(@"/*QPT:::AUTOGENERATED*/

//////////////////////////////////////////////////////////////////////
////       AUTO-GENERATED WITH  PokoObjectCacheWriter     ////
//////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Qorpent.Data;
using Qorpent.Data.DataCache;
using Qorpent.Utils.Extensions;
using Test.Adapters;
namespace Test.ObjectCaches {
	///<summary>
	/// Object cache for B
	///</summary>
	public partial class BDataCache : ObjectDataCache<B> {
		///<summary>Creates cache with typed adapter </summary>
		public BDataCache() {
		}
		///<summary>Back reference to model</summary>
		public Test.Adapters.Model Model {get;set;}

		///<summary>Тест TF (Id notation)</summary>
		public A[] GetA (long bId) {
			return Model.A.GetAll (""select id from \""dbo\"".\""bGetA\"" ( '""+bId+""')"");
		}

		///<summary>Тест TF (Code notation)</summary>
		public A[] GetA (string bCode) {
			return Model.A.GetAll (""select id from \""dbo\"".\""bGetA\"" ( '""+bCode+""')"");
		}

		///<summary>Тест TF</summary>
		public A[] GetA (B b) {
			return GetA (b.Id);
		}
	}
}
".Trim().LfOnly(), code.Trim().LfOnly());
        }