コード例 #1
0
        static public string GetTableSelect(string provider, IDbConnection cn)
        {
            if (SqlEntries == null)
            {
                EngineConfigInit();
            }
            SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;

            if (sce == null)
            {
                if (cn != null)
                {
                    OdbcConnection oc = cn as OdbcConnection;
                    if (oc != null && oc.Driver.ToLower().IndexOf("my") >= 0) // not a good way but ...
                    {
                        return("show tables");                                // mysql syntax is non-standard
                    }
                }
                return("SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES ORDER BY 2, 1");
            }
            if (cn != null)
            {
                OdbcConnection oc = cn as OdbcConnection;
                if (oc != null && oc.Driver.ToLower().IndexOf("my") >= 0) // not a good way but ...
                {
                    return("show tables");                                // mysql syntax is non-standard
                }
            }
            return(sce.TableSelect);
        }
コード例 #2
0
        static public bool DoParameterReplacement(string provider, IDbConnection cn)
        {
            if (SqlEntries == null)
            {
                EngineConfigInit();
            }
            SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;

            return(sce == null ? false : sce.ReplaceParameters);
        }
コード例 #3
0
        public static IDbConnection GetConnection(string provider, string cstring)
        {
            IDbConnection cn = null;

            switch (provider.ToLower())
            {
            case "sql":
                // can't connect unless information provided;
                //   when user wants to set the connection programmatically this they should do this
                if (cstring.Length > 0)
                {
                    cn = new SqlConnection(cstring);
                }
                break;

            case "odbc":
                cn = new OdbcConnection(cstring);
                break;

            case "oledb":
                cn = new OleDbConnection(cstring);
                break;

            default:
                if (SqlEntries == null)             // if never initialized; we should init
                {
                    EngineConfigInit();
                }
                SqlConfigEntry sce = SqlEntries[provider] as SqlConfigEntry;
                if (sce == null || sce.CodeModule == null)
                {
                    if (sce != null && sce.ErrorMsg != null)       // error during initialization??
                    {
                        throw new Exception(sce.ErrorMsg);
                    }
                    break;
                }
                object[] args = new object[] { cstring };
                Assembly asm  = sce.CodeModule;
                object   o    = asm.CreateInstance(sce.ClassName, false,
                                                   BindingFlags.CreateInstance, null, args, null, null);
                if (o == null)
                {
                    throw new Exception(string.Format("Unable to create instance of '{0}' for provider '{1}'", sce.ClassName, provider));
                }
                cn = o as IDbConnection;
                break;
            }

            return(cn);
        }
コード例 #4
0
        static void GetDataSource(IDictionary dsDir, XmlNode xNode)
        {
            string provider          = null;
            string codemodule        = null;
            string cname             = null;
            string inter             = "SQL";
            string tselect           = null;
            bool   replaceparameters = false;

            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (xNodeLoop.Name)
                {
                case "DataProvider":
                    provider = xNodeLoop.InnerText;
                    break;

                case "CodeModule":
                    codemodule = xNodeLoop.InnerText;
                    break;

                case "Interface":
                    inter = xNodeLoop.InnerText;
                    break;

                case "ClassName":
                    cname = xNodeLoop.InnerText;
                    break;

                case "TableSelect":
                    tselect = xNodeLoop.InnerText;
                    break;

                case "ReplaceParameters":
                    if (xNodeLoop.InnerText.ToLower() == "true")
                    {
                        replaceparameters = true;
                    }
                    break;

                default:
                    break;
                }
            }
            if (provider == null)
            {
                return;         // nothing to do if no provider specified
            }
            SqlConfigEntry sce;

            try
            {   // load the module early; saves problems with concurrency later
                string   msg = null;
                Assembly la  = null;
                if (codemodule != null && cname != null)
                {
                    // check to see if the DLL has been previously loaded
                    //   many of the DataProvider done by ReportingCloud are in a single code module
                    foreach (SqlConfigEntry sc in dsDir.Values)
                    {
                        if (sc.FileName == codemodule &&
                            sc.CodeModule != null)
                        {
                            la = sc.CodeModule;
                            break;
                        }
                    }
                    if (la == null)
                    {
                        la = XmlUtil.AssemblyLoadFrom(codemodule);
                    }
                    if (la == null)
                    {
                        msg = string.Format("{0} could not be loaded", codemodule);
                    }
                }
                sce = new SqlConfigEntry(provider, codemodule, cname, la, tselect, msg);
                dsDir.Add(provider, sce);
            }
            catch (Exception e)
            {      // keep exception;  if this DataProvided is ever useed we will see the message
                sce = new SqlConfigEntry(provider, codemodule, cname, null, tselect, e.Message);
                dsDir.Add(provider, sce);
            }
            sce.ReplaceParameters = replaceparameters;
        }
コード例 #5
0
        static void GetDataSource(IDictionary dsDir, XmlNode xNode)
        {
            string provider = null;
            string codemodule = null;
            string cname = null;
            string inter = "SQL";
            string tselect = null;
            bool replaceparameters = false;
            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                    continue;
                switch (xNodeLoop.Name)
                {
                    case "DataProvider":
                        provider = xNodeLoop.InnerText;
                        break;
                    case "CodeModule":
                        codemodule = xNodeLoop.InnerText;
                        break;
                    case "Interface":
                        inter = xNodeLoop.InnerText;
                        break;
                    case "ClassName":
                        cname = xNodeLoop.InnerText;
                        break;
                    case "TableSelect":
                        tselect = xNodeLoop.InnerText;
                        break;
                    case "ReplaceParameters":
                        if (xNodeLoop.InnerText.ToLower() == "true")
                            replaceparameters = true;
                        break;
                    default:
                        break;
                }
            }
            if (provider == null)
                return;         // nothing to do if no provider specified

            SqlConfigEntry sce;
            try
            {   // load the module early; saves problems with concurrency later
                string msg = null;
                Assembly la = null;
                if (codemodule != null && cname != null)
                {
                    // check to see if the DLL has been previously loaded
                    //   many of the DataProvider done by ReportingCloud are in a single code module
                    foreach (SqlConfigEntry sc in dsDir.Values)
                    {
                        if (sc.FileName == codemodule &&
                            sc.CodeModule != null)
                        {
                            la = sc.CodeModule;
                            break;
                        }
                    }
                    if (la == null)
                        la = XmlUtil.AssemblyLoadFrom(codemodule);
                    if (la == null)
                        msg = string.Format("{0} could not be loaded", codemodule);
                }
                sce = new SqlConfigEntry(provider, codemodule, cname, la, tselect, msg);
                dsDir.Add(provider, sce);
            }
            catch (Exception e)
            {      // keep exception;  if this DataProvided is ever useed we will see the message
                sce = new SqlConfigEntry(provider, codemodule, cname, null, tselect, e.Message);
                dsDir.Add(provider, sce);
            }
            sce.ReplaceParameters = replaceparameters;
        }