initDb() публичный Метод

public initDb ( string connect ) : bool
connect string
Результат bool
Пример #1
0
        private bool pGetData(
            ref DataTable vRows,
            ref DataTable rs,
            cReportConnect connect,
            bool createIndexVector,
            List<object[]> recordsets)
        {
            String strConnect = "";
            bool saveInReport = false;
            CSDataBase.cDataBase cn = null;
            object[] varRs = null;
            DataTable rsAux = null;
            DbDataReader dr = null;

            // if we get an string connection
            //
            if (m_launchInfo.getStrConnect().Trim() != "")
            {
                strConnect = m_launchInfo.getStrConnect();
            }
            // if m_launchInfo.getStrConnect() is empty we will use
            // the connection of the connect object
            // 
            else
            {
                strConnect = connect.getStrConnect();
                saveInReport = true;
            }
            if (!getReportDisconnected())
            {
                if (strConnect.Trim() == "")
                {
                    cWindow.msgWarning("The connection settings were not defined."
                                        + "Both the LaunchInfo and the Connect object have their "
                                        + "strConnect property empty. Whitout this connection string "
                                        + "it will be imposible to open the connection to the database.",
                                        "CSReportEditor");
                    return false;
                }

                cn = new cDataBase(m_databaseEngine);

                if (m_isForWeb)
                {
                    cn.setSilent(true);
                }
                if (connect.getCommandTimeout() > 0)
                {
                    cn.setCommandTimeout(connect.getCommandTimeout());
                }
                if (connect.getConnectionTimeout() > 0)
                {
                    cn.setConnectionTimeout(connect.getConnectionTimeout());
                }

                // open the connection
                //
                if (!cn.initDb("", "", "", "", strConnect))
                {
                    if (!resumeDBAccessMissing(strConnect, saveInReport, cn))
                    {
                        return false;
                    }
                }

                // we need to prepare the first sentence
                //
                String sqlstmt = "";

                // if it was a select
                //
                if (m_launchInfo.getSqlstmt().Trim() != "")
                {
                    sqlstmt = m_launchInfo.getSqlstmt();
                }
                else
                {
                    if (connect.getDataSourceType() == csDataSourceType.CDDTPROCEDURE)
                    {
                        sqlstmt = "exec [" + connect.getDataSource() + "] " + connect.getSqlParameters();
                    }
                    else if (connect.getDataSourceType() == csDataSourceType.CSDTTABLE)
                    {
                        sqlstmt = "select * from [" + connect.getDataSource() + "]";
                    }
                    else
                    {
                        sqlstmt = connect.getDataSource();
                    }
                }

                // open the recordset
                //
                cn.setOpenRsExDescript(m_descripUser);

                if (!cn.loadDataTable(true,
                                        false,
                                        false,
                                        sqlstmt,
                                        out rs,
                                        out dr,
                                        "GetData",
                                        C_MODULE,
                                        ""))
                {
                    return false;
                }

                if (rs.Rows.Count == 0)
                {
                    vRows = null;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[0];
                        m_lastRowIndex = -1;
                    }
                }
                else
                {
                    vRows = rs;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[vRows.Rows.Count];
                        m_lastRowIndex = m_vRowsIndex.Length - 1;
                        int k = 0;
                        for (k = 0; k < m_vRowsIndex.Length; k++)
                        {
                            m_vRowsIndex[k] = k;
                        }
                    }
                }

                varRs = new object[2];
                varRs[0] = rs;
                varRs[1] = connect.getDataSource();
                recordsets.Add(varRs);

                // we need to load every recordset from every data source
                // in the recordset collection (this code suport multiples
                // recordset in the same reader)
                //
                while (!dr.IsClosed && dr.NextResult())
                {
                    rsAux = new DataTable();
                    rsAux.Load(dr);
                    
                    varRs = new object[2];
                    varRs[0] = rsAux;
                    varRs[1] = connect.getDataSource();
                    recordsets.Add(varRs);

                    // TODO: check if this works
                    //
                    // we add an empty element to m_collRows to avoid
                    // index of bounds exception
                    //
                    G.redimPreserve(ref m_collRows, m_collRows.Length + 1);
                }

                cn.closeDb();
            }
            else
            {
                vRows = null;
                if (createIndexVector)
                {
                    m_vRowsIndex = new int[0];
                    m_lastRowIndex = -1;
                }
            }
            if (m_rows != null)
            {
                m_recordCount = m_vRowsIndex.Length;
            }
            else
            {
                m_recordCount = 0;
            }
            m_iRow = 0;
            m_idxGroupHeader = -1;
            m_idxGroupFooter = -1;

            return true;
        }
Пример #2
0
 private bool fillColumns(string sqlstmt)
 {
     var db = new cDataBase(csDatabaseEngine.SQL_SERVER);
     if (db.initDb(m_strConnect))
     {
         DbDataReader rs;
         if (db.openRs(sqlstmt, out rs, "fillColumns", "cConnect", "Update columns's definition", CSKernelClient.eErrorLevel.eErrorInformation))
         {
             for (int i = 0; i < rs.FieldCount; i++)
             {
                 var column = new cColumnInfo();
                 column.setName(rs.GetName(i));
                 column.setPosition(i);
                 column.setColumnType((csDataType)System.Type.GetTypeCode((rs.GetFieldType(i))));
                 m_columnsInfo.add(column, "");
             }
         }
         else
         {
             return false;
         }
     }
     return true;
 }
Пример #3
-35
        public bool fillParameters(string dataSource)
        {
            cDataBase db = new cDataBase(csDatabaseEngine.SQL_SERVER);
            if (db.initDb(m_strConnect))
            {
                string[] restrictions = new string[4];
                restrictions[2] = dataSource;
                DataTable dt = db.openSchema("ProcedureParameters", restrictions);

                if (m_parameters == null) m_parameters = new cParameters();

                cParameters parameters = new cParameters();

                foreach (DataRow row in dt.Rows)
                {
                    if (row["parameter_mode"].ToString() != "OUT") 
                    {
                        cParameter p = null;
                        bool found = false;
                        for (var i = 0; i < m_parameters.count(); i++)
                        { 
                            p = m_parameters.item(i);
                            if (p.getName() == row["parameter_name"].ToString())
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found) p = null;
                        p = parameters.add(p, "");
                        p.setName(row["parameter_name"].ToString());
                        p.setPosition((int)row["ordinal_position"]);
                        p.setColumnType(cDatabaseGlobals.getDataTypeFromString(row["data_type"].ToString()));
                    }
                }
                //
                // openSchema can be sorted by any column (usually by name)
                // we need this collection to be sorted by position
                //
                m_parameters = new cParameters();

                for (var j = 1; j < parameters.count() + 1; j++)
                {
                    cParameter p = null;
                    bool found = false;
                    for (var i = 0; i < parameters.count(); i++)
                    {
                        p = parameters.item(i);
                        if (p.getPosition() == j)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        throw new Exception("Parameter not found for position: " + j);
                    }
                    else
                    {
                        m_parameters.add(p, p.getKey());
                    }
                }
                
                return true;
            }

            return false;
        }