System.Data.SQLite
Check-in [a42d12707e]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test for a REGEXP operator implemented using the Regex class.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a42d12707e97c3f782c06eb05e333fe86b8e9acf
User & Date: mistachkin 2016-06-30 02:42:30
Context
2016-07-01
03:20
Correct an attribution comment. check-in: 8c08bda9a1 user: mistachkin tags: trunk
2016-06-30
02:42
Add test for a REGEXP operator implemented using the Regex class. check-in: a42d12707e user: mistachkin tags: trunk
2016-06-28
17:19
Add the new constraint operators. Fix for ticket [47182b7f82]. check-in: 349fd3a23e user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Tests/basic.eagle.

4230
4231
4232
4233
4234
4235
4236
4237
4238
4239

































































































































































































4240
4241
4242
4243
4244
4245
4246
  cleanupDb $fileName

  unset -nocomplain error result db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {0 False 1 {unknown error -- database "wrong" not\
found} 0 True 1 {unknown error -- database "wrong" not found} 0 False 1\
{unknown error -- database "wrong" not found}}}

###############################################################################


































































































































































































reportSQLiteResources $test_channel

###############################################################################

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
  cleanupDb $fileName

  unset -nocomplain error result db fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite} -result {0 False 1 {unknown error -- database "wrong" not\
found} 0 True 1 {unknown error -- database "wrong" not found} 0 False 1\
{unknown error -- database "wrong" not found}}}

###############################################################################

runTest {test data-1.83 {bind and use REGEXP function} -setup {
  set fileName data-1.83.db
} -body {
  set id [object invoke Interpreter.GetActive NextId]
  set dataSource [file join [getDatabaseDirectory] $fileName]

  set sql(1) { \
    SELECT 'test' REGEXP '^t.?.?t$'; \
  }

  set sql(2) { \
    SELECT 'no' REGEXP '^nope$'; \
  }

  unset -nocomplain results errors

  set code [compileCSharpWith [subst {
    using System;
    using System.Data.SQLite;
    using System.Text.RegularExpressions;

    namespace _Dynamic${id}
    {
      public class Test${id} : SQLiteFunction
      {
        private static SQLiteFunctionAttribute functionAttribute;
        private static SQLiteConnection connection;

        ///////////////////////////////////////////////////////////////////////

        public override object Invoke(
          object\[\] args
          )
        {
          if (args == null)
            return new ArgumentNullException("args");

          if (args.Length != 2)
            return new ArgumentException(String.Format(
              "need exactly two arguments, got {0}", args.Length));

          string pattern = (args\[0\] != null) ? args\[0\].ToString() : null;

          if (pattern == null)
            return new ArgumentNullException("pattern");

          string input = (args\[1\] != null) ? args\[1\].ToString() : null;

          if (input == null)
            return new ArgumentNullException("input");

          return Regex.IsMatch(input, pattern);
        }

        ///////////////////////////////////////////////////////////////////////

        private static void Initialize()
        {
          if (functionAttribute == null)
          {
            functionAttribute = new SQLiteFunctionAttribute(
                "regexp", 2, FunctionType.Scalar);
          }

          if (connection == null)
          {
            connection = new SQLiteConnection(
                "Data Source=${dataSource};[getFlagsProperty]");

            connection.Open();
          }
        }

        ///////////////////////////////////////////////////////////////////////

        public static void BindFunction()
        {
          Initialize();

          connection.BindFunction(functionAttribute, new Test${id}());
        }

        ///////////////////////////////////////////////////////////////////////

        public static object CallFunction1()
        {
          Initialize();

          using (SQLiteCommand command = new SQLiteCommand("${sql(1)}",
              connection))
          {
            return command.ExecuteScalar();
          }
        }

        ///////////////////////////////////////////////////////////////////////

        public static object CallFunction2()
        {
          Initialize();

          using (SQLiteCommand command = new SQLiteCommand("${sql(2)}",
              connection))
          {
            return command.ExecuteScalar();
          }
        }

        ///////////////////////////////////////////////////////////////////////

        public static bool UnbindFunction()
        {
          Initialize();

          return connection.UnbindFunction(functionAttribute);
        }

        ///////////////////////////////////////////////////////////////////////

        public static void Uninitialize()
        {
          if (connection != null)
          {
            connection.Close();
            connection = null;
          }

          if (functionAttribute != null)
            functionAttribute = null;
        }

        ///////////////////////////////////////////////////////////////////////

        public static void Main()
        {
          // do nothing.
        }
      }
    }
  }] true true true results errors System.Data.SQLite.dll]

  list $code $results \
      [expr {[info exists errors] ? $errors : ""}] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction1
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction2
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} BindFunction
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction1
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction2
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} UnbindFunction
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction1
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} CallFunction2
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} Uninitialize
      } result] : [set result ""]}] \
      [extractSystemDataSQLiteExceptionMessage $result]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result code results errors sql dataSource id fileName
} -constraints {eagle command.object monoBug28 command.sql compile.DATA SQLite\
System.Data.SQLite compileCSharp} -match regexp -result {^Ok\
System#CodeDom#Compiler#CompilerResults#\d+ \{\} 1 \{SQL logic error or missing\
database -- no such function: REGEXP\} 1 \{SQL logic error or missing database\
-- no such function: REGEXP\} 0 \{\} 0 1 0 0 0 True 1 \{SQL logic error or\
missing database -- no such function: REGEXP\} 1 \{SQL logic error or missing\
database -- no such function: REGEXP\} 0 \{\}$}}

###############################################################################

reportSQLiteResources $test_channel

###############################################################################

runSQLiteTestFilesEpilogue
runSQLiteTestEpilogue
runTestEpilogue