Пример #1
0
        private string GetColumnImage(string imageID, string column, string fileName)
        {
            string retImageFullName = "";

            if (_odbcConnection == null)
            {
                return(retImageFullName);
            }

            //ODBC Access
            System.Data.Odbc.OdbcCommand    odbcCommand = null;
            System.Data.Odbc.OdbcDataReader odbcRead    = null;

            try
            {
                odbcCommand = new System.Data.Odbc.OdbcCommand();

                odbcCommand.CommandText = "SELECT " + column + " FROM DBSDESX.CHVT34A0_IMAGENS WHERE CREFARQ = '" + imageID + "'";

                odbcCommand.Connection = _odbcConnection;

                odbcRead = odbcCommand.ExecuteReader();  //System.Data.CommandBehavior.SequentialAccess
                //byte[] _buf = (byte[]) odbcCommand.ExecuteScalar();

                //if (!odbcRead.Read())
                //    return retImageFullName; //not found
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            //Read BLOB
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            int bufferSize = 100;

            byte[] outByte = new byte[bufferSize];
            long   retval;
            long   startIndex = 0;

            try
            {
                // Read bytes into outByte[] and retain the number of bytes returned.
                retval = odbcRead.GetBytes(0, startIndex, outByte, 0, bufferSize);

                // Continue while there are bytes beyond the size of the buffer.
                while (retval == bufferSize)
                {
                    //Write the buffer. (convert byte to char)
                    for (int i = 0; i < retval; i++)
                    {
                        sb.Append(System.Convert.ToChar(outByte[i]));
                    }

                    // Reposition start index to end of last buffer and fill buffer.
                    startIndex += bufferSize;
                    retval      = odbcRead.GetBytes(0, startIndex, outByte, 0, bufferSize);
                }

                // Write the remaining buffer. (convert byte to char)
                for (int i = 0; i < retval; i++)
                {
                    sb.Append(System.Convert.ToChar(outByte[i]));
                }
            }
            catch
            {
            }

            //Close DB2 reader
            try
            {
                odbcRead.Close();
                odbcCommand.Dispose();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }


            //Create file
            try
            {
                if (sb.Length > 0)
                {
                    string myDocFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonPictures) + "\\";

                    string text = sb.ToString();
                    byte[] base64EncodedBytes = System.Convert.FromBase64String(text);

                    System.IO.File.WriteAllBytes(myDocFolder + fileName, base64EncodedBytes);
                    retImageFullName = myDocFolder + fileName;
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

            return(retImageFullName);
        }
Пример #2
0
        // <summary>
        /// recompute indexes for selected table
        /// to speed up queries
        /// </summary>
        /// <returns></returns>
        public static void UpdateIndexes(string tableType, DbConnect dbConnect)
        {
            ProtCidSettings.progressInfo.ResetCurrentProgressInfo();
            DbQuery dbQuery = new DbQuery();

            try
            {
                System.Data.Odbc.OdbcCommand updateIndexCommand = dbConnect.CreateCommand();

                // retrieve user-defined indexes
                string showIndexStr = @"select RDB$INDEX_NAME, RDB$RELATION_NAME from RDB$INDICES WHERE RDB$SYSTEM_FLAG = 0;";
                //string showIndexStr = @"select RDB$INDEX_NAME from RDB$INDICES;";
                updateIndexCommand.CommandText = showIndexStr;
                System.Data.Odbc.OdbcDataReader indexReader = updateIndexCommand.ExecuteReader();
                //	ArrayList indexList = new ArrayList ();
                Dictionary <string, List <string> > relationIndexHash = new Dictionary <string, List <string> > ();
                string indexName    = "";
                string relationName = "";
                if (indexReader.HasRows)
                {
                    while (indexReader.Read())
                    {
                        relationName = indexReader.GetString(1).Trim().ToUpper();
                        if (relationName.IndexOf(tableType.ToUpper()) > -1)
                        {
                            indexName = indexReader.GetString(0).Trim().ToUpper();

                            if (relationIndexHash.ContainsKey(relationName))
                            {
                                relationIndexHash[relationName].Add(indexName);
                            }
                            else
                            {
                                List <string> relationIndexList = new List <string> ();
                                relationIndexList.Add(indexName);
                                relationIndexHash.Add(relationName, relationIndexList);
                            }
                        }
                    }
                    indexReader.Close();
                }
                foreach (string relationTable in relationIndexHash.Keys)
                {
                    foreach (string index in relationIndexHash[relationTable])
                    {
                        // rebuild this index for cryst and interface
                        if (indexName.ToString().ToUpper().IndexOf("RDB$PRIMARY") == -1)
                        {
                            string inactiveIndexStr = string.Format("ALTER INDEX {0} INACTIVE;", index);
                            updateIndexCommand.CommandText = inactiveIndexStr;
                            updateIndexCommand.ExecuteNonQuery();
                            string activeIndexStr = string.Format("ALTER INDEX {0} ACTIVE;", index);
                            updateIndexCommand.CommandText = activeIndexStr;
                            updateIndexCommand.ExecuteNonQuery();
                        }
                        // recompute selectivity of this index
                        string updateSelectivityStr = string.Format("SET STATISTICS INDEX {0};", index);
                        updateIndexCommand.CommandText = updateSelectivityStr;
                        updateIndexCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                // Displays the Error Message in the progress label.
                ProtCidSettings.progressInfo.progStrQueue.Enqueue("Update Indexes Errors: " + ex.Message);
            }
        }