Using regular expressions in Oracle SQL queries, pt. II

This is a second part of an article on regular expressions usage in Oracle. This part contains SQL examples only, for more details about functions and their parameters see first part of this article.

Regular expressions used in examples are very simple as this is no publication about regular expressions itself.

Using regular expressions in Oracle on actual tables

Let's say we have this simple table (users):

id login name city email
1 jd John Doe Washington j.doe@abcxyz.com
2 ivan Ivan Ivanovich Moscow ivan@qwerty.ru
3 jane84 Jane Doe Washington jane@abcxyz.com
4 jn2501 Juan Nadie Madrit juan@nadie.biz

Grasshopper 1.3.0.102 release info


We are happy to announce another Grasshopper release!
  • Visit project summary page to get more details about general features.
  • Please feel free to leave a comment here on any usage difficulties or benefits of this version.
Give Grasshopper a try to see what it's really capable of!

Submitted changes:

Best Practices for Assembly Loading for portable applications

Some of you have certainly met with many different aspects of developing applications based on extensions. The following publication raises the question of practices for extensions in portable applications.

On msdn pages you will find well designed in theory and with almost identical title as ours: Best Practices for Assembly Loading . In short - we get a knowledge of the 'pros and cons' of different approaches and although unfortunately article lacks of practical examples it is worth to get familiar with it.
 

Using regular expressions in Oracle SQL queries, pt. I

This is an article on Oracle and using of regular expressions. Oracle has several regexp functions. Each will be described with an example below.

First things first

If you have access to existing Oracle database you can skip to the next paragraph.
If you don’t have Oracle database installed already, please follow these steps:

  • register at oracle.com
  • download and install latest possible Oracle Database*
* at the moment you can get 10g Express Edition [Universal] here:

GoldenSharp [beta] 0.9.0.52 release info


We are happy to announce GoldenSharp first release!
  • Visit project summary page to get more details about general features.
  • This is a beta release and as such may be unstable. Please let us know about any errors that you encounter or you can leave a comment here on any feature requests, usage difficulties or benefits of this version.
  • GoldenSharp in beta release connects to Karmian Update Service on application startup. Keeping all features and bug fixes up to date is necessary in our opinion.

Give GoldenSharp a try to see what it's really capable of!

LINQ lambda expressions in universal generic equality comparer

Implementation

Below you can find implementation we use as universal equality comparer. Only lambda expressions as in LINQ queries are needed to measure items. Class LambdaComparer is generic, so you can use it on any type you want to.

LambdaComparer class

using System;
using System.Collections.Generic;
 
namespace Karmian.Framework.Helpers
{
    public class LambdaComparer<T> : IEqualityComparer<T>
    {
        public LambdaComparer(Func<T, T, bool> equals, Func<T, int> getHashCode)
        {
            _equals = equals;
            _getHashCode = getHashCode;
        }
 
        readonly Func<T, T, bool> _equals;
        public bool Equals(T x, T y)
        {
            return _equals(x, y);
        }
 
        readonly Func<T, int> _getHashCode;
        public int GetHashCode(T obj)
        {
            return _getHashCode(obj);
        }
    } 
}

Running executable from MemoryStream / Resources / binary array

Be aware, that executables or assemblies loaded in such manner share main application (host) domain. This implies that if there is any reference needed other from GAC (GlobalAssemblyCache) or host working directory - you will need to handle AppDomain.CurrentDomain.AssemblyResolve event or create new AppDomain for example. Sample code:
using System;
using System.IO;
using System.Reflection;
 
namespace ExecutableMemoryStream
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                    throw new TargetParameterCountException(
                             "Expected at least one parameter containing executable path.");
 
                using (FileStream fileStream = new FileStream(args[0], FileMode.Open))
                using (BinaryReader reader = new BinaryReader(fileStream))
                {
                    byte[] bin = reader.ReadBytes(Convert.ToInt32(fileStream.Length));
                    Assembly assembly = Assembly.Load(bin);
                    MethodInfo method = assembly.EntryPoint;
                    if (method != null)
                    {
                        object o = assembly.CreateInstance(method.ReflectedType.Name);
                        if (method.GetParameters().Length == 0)
                            method.Invoke(o, new object[0]);
                        else
                        {
                            string[] parameters = new string[args.Length - 1];
                            for (int i = 1; i < args.Length; i++)
                                parameters[i - 1] = args[i];
                            method.Invoke(o, new[] { parameters });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
                Console.WriteLine(ex.Message.PadRight(80));
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Hit 'd' for details. Any other key will terminate application.");
                if (Console.ReadKey(true).KeyChar == 'd')
                {
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine();
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadKey();
                }
            }
        }
    }
}
Syndicate content