Esempio n. 1
1
		public static void LogCommand(DBCmd cmd, string text) {
			WriteLine(string.Format("Executing command {0} with text ='{1}'", cmd, text));
		}
Esempio n. 2
0
		static public void LogCommand( DBCmd cmd, string text)
		{
			string msg = String.Format("Executing command {0} with text ='{1}'", cmd, text);
			//TODO: check this
				//Enum.GetName( typeof(DBCmd), cmd ), text );
			WriteLine( msg );
		}
Esempio n. 3
0
 private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
 {
     try
     {
         this.SequenceByte = 0;
         int num = 1;
         if (bytes != null)
         {
             num += length;
         }
         this.writer.StartPacket((long)num);
         this.writer.WriteByte((byte)cmd);
         if (bytes != null)
         {
             this.writer.Write(bytes, 0, length);
         }
         this.writer.Flush();
     }
     catch (MySqlException ex)
     {
         if (ex.IsFatal)
         {
             this.isOpen = false;
             this.Close();
         }
         throw;
     }
 }
Esempio n. 4
0
        public CommandResult Send(DBCmd cmd, byte[] bytes)
        {
//			string s = Encoding.GetString( bytes );

            Packet packet = CreatePacket(null);

            packetSeq = 0;
            packet.WriteByte((byte)cmd);
            if (bytes != null)
            {
                packet.Write(bytes, 0, bytes.Length);
            }

            SendPacket(packet);
            packet = ReadPacket();

            // first check to see if this is a LOAD DATA LOCAL callback
            // if so, send the file and then read the results
            long fieldcount = packet.ReadLenInteger();

            if (fieldcount == Packet.NULL_LEN)
            {
                string filename = packet.ReadString();
                SendFileToServer(filename);
                packet = ReadPacket();
            }
            else
            {
                packet.Position = 0;
            }

            return(new CommandResult(packet, this));
        }
Esempio n. 5
0
        static public void LogCommand(DBCmd cmd, string text)
        {
            string msg = String.Format("Executing command {0} with text ='{1}'", cmd, text);

            //TODO: check this
            //Enum.GetName( typeof(DBCmd), cmd ), text );
            WriteLine(msg);
        }
Esempio n. 6
0
 public static void LogCommand(DBCmd cmd, string text)
 {
     if (text.Length > 300)
     {
         text = text.Substring(0, 300);
     }
     string.Format("Executing command {0} with text ='{1}'", Enum.GetName(typeof(DBCmd), cmd), text);
 }
Esempio n. 7
0
        /// <summary>
        /// Sends the specified command to the database
        /// </summary>
        /// <param name="command">Command to execute</param>
        /// <param name="text">Text attribute of command</param>
        /// <returns>Result packet returned from database server</returns>
        public void Send(DBCmd command, String text)
        {
            CommandResult result = Send(command, this.Encoding.GetBytes(text));

            if (result.IsResultSet)
            {
                throw new MySqlException("SendCommand failed for command " + text);
            }
        }
Esempio n. 8
0
        public System.IO.StringWriter Download(string name, string info)
        {
            string spname = info;

            //System.IO.StringWriter writer = new System.IO.StringWriter();

            //return writer2;

            using (DB db = DBMgr.Instance.GetDB("DefaultConnection"))
            {
                if (string.IsNullOrWhiteSpace(spname) == false)
                {
                    DBCmd cmd = db.NewCommand(spname);

                    DBReader reader = db.Execute(cmd);

                    var cols = reader.ColumnCount;

                    using (var stringy = new System.IO.StringWriter())
                    {
                        using (var writer = new CsvWriter(stringy))
                        {
                            if (cols > 0)
                            {
                                for (int i = 0; i < cols - 1; i++)
                                {
                                    writer.WriteField(reader.get_GetColumnName(i));
                                }

                                writer.NextRecord();

                                while (reader.Read())
                                {
                                    for (int i = 0; i < cols - 1; i++)
                                    {
                                        writer.WriteField(reader.GetString(i));
                                    }

                                    writer.NextRecord();
                                }
                            }
                        }

                        return(stringy);
                    }
                }
            }


            return(null);
        }
Esempio n. 9
0
        static public void LogCommand(DBCmd cmd, string text)
        {
            if (text.Length > 300)
            {
                text = text.Substring(0, 300);
            }

            string msg = String.Format("Executing command {0} with text ='{1}'",
                                       cmd.ToString(), text);

            //TODO: check this
            //Enum.GetName( typeof(DBCmd), cmd ), text );
            WriteLine(msg);
        }
Esempio n. 10
0
        private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
        {
            SequenceByte = 0;
            int len = 1;

            if (bytes != null)
            {
                len += length;
            }
            writer.StartPacket(len);
            writer.WriteByte((byte)cmd);
            if (bytes != null)
            {
                writer.Write(bytes, 0, length);
            }
            writer.Flush();
        }
Esempio n. 11
0
        // 執行SQL操作指令:INSERT、UPDATE、DELETE…
        static public int executeSQL(string DBName, string SQLStr, ArrayList Parameter = null)
        {
            int        rowCount = 0;
            IDbCommand DBCmd    = null;

            try
            {
                if (ConfigurationManager.ConnectionStrings[DBName].ConnectionString.IndexOf("Provider=SQLOLEDB") >= 0)
                {
                    DBCmd = new OleDbCommand(SQLStr, new OleDbConnection(ConfigurationManager.ConnectionStrings[DBName].ConnectionString));
                    if (Parameter != null)                  // 設定查詢參數
                    {
                        for (int i = 0; i < Parameter.Count; i++)
                        {
                            DBCmd.Parameters.Add(new OleDbParameter(i.ToString(), Parameter[i]));
                        }
                    }
                }
                else
                {
                    DBCmd = new SqlCommand(SQLStr, new SqlConnection(ConfigurationManager.ConnectionStrings[DBName].ConnectionString));
                    if (Parameter != null)                  // 設定查詢參數
                    {
                        for (int i = 0; i < Parameter.Count; i++)
                        {
                            DBCmd.Parameters.Add(new SqlParameter(i.ToString(), Parameter[i]));
                        }
                    }
                }

                DBCmd.Connection.Open();
                rowCount = DBCmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                DBCmd.Connection.Close();
            }

            return(rowCount);
        }
Esempio n. 12
0
 private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
 {
     try {
         this.stream.StartOutput((ulong)(length + 1L), true);
         this.stream.WriteByte((byte)cmd);
         if (length > 0)
         {
             this.stream.Write(bytes, 0, length);
         }
         this.stream.Flush();
     } catch (MySqlException exception) {
         if (exception.IsFatal)
         {
             base.isOpen = false;
             this.Close();
         }
         throw;
     }
 }
Esempio n. 13
0
        /// <summary>
        /// ExecuteCommand does the work of writing the actual command bytes to the writer
        /// We break it out into a function since it is used in several places besides query
        /// </summary>
        /// <param name="cmd">The cmd that we are sending</param>
        /// <param name="bytes">The bytes of the command, can be null</param>
        /// <param name="length">The number of bytes to send</param>
        private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
        {
            Debug.Assert(length == 0 || bytes != null);

            try
            {
                stream.StartOutput((ulong)length + 1, true);
                stream.WriteByte((byte)cmd);
                if (length > 0)
                {
                    stream.Write(bytes, 0, length);
                }
                stream.Flush();
            }
            catch (MySqlException ex)
            {
                if (ex.IsFatal)
                {
                    isOpen = false;
                    Close();
                }
                throw;
            }
        }
        public System.IO.StringWriter Download(string name, string info)
        {
            string spname = info;

            List <string> jsonValues = new List <string>();

            //jsonValues = (List<string>)value;

            using (DB db = DBMgr.Instance.GetDB("DefaultConnection"))
            {
                if (string.IsNullOrWhiteSpace(spname) == false)
                {
                    DBCmd cmd = db.NewCommand(spname);

                    DBReader reader = db.Execute(cmd);

                    while (reader.Read())
                    {
                        jsonValues.Add(reader.GetString(0));
                    }
                }
            }

            if (jsonValues != null)
            {
                List <string> header;

                header = ReporterHelpers.GetHeader(jsonValues);

                using (System.IO.StringWriter stringy = new System.IO.StringWriter())
                {
                    using (CsvWriter writer = new CsvWriter(stringy))
                    {
                        if (header != null && header.Count() > 0)
                        {
                            foreach (var h in header)
                            {
                                writer.WriteField(h);
                            }

                            writer.NextRecord();
                        }

                        for (int i = 0; i < jsonValues.Count() - 1; i++)
                        {
                            var d = headspin.jsonutilities.JsonHelper.DeserializeAndFlatten(jsonValues[i]);

                            foreach (var h in header)
                            {
                                var currField = (from y in d
                                                 where y.Key == h
                                                 select y.Value);

                                if (currField != null)
                                {
                                    writer.WriteField(currField.FirstOrDefault());
                                }
                                else
                                {
                                    writer.WriteField("");
                                }
                            }

                            writer.NextRecord();
                        }

                        return(stringy);
                    }
                }
            }

            return(null);
        }
Esempio n. 15
0
        /// <summary>
        /// ExecuteCommand does the work of writing the actual command bytes to the writer
        /// We break it out into a function since it is used in several places besides query
        /// </summary>
        /// <param name="cmd">The cmd that we are sending</param>
        /// <param name="bytes">The bytes of the command, can be null</param>
        /// <param name="length">The number of bytes to send</param>
        private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
        {
            Debug.Assert(length == 0 || bytes != null);

            try
            {
                stream.StartOutput((ulong) length + 1, true);
                stream.WriteByte((byte) cmd);
                if (length > 0)
                    stream.Write(bytes, 0, length);
                stream.Flush();
            }
            catch (MySqlException ex)
            {
                if (ex.IsFatal)
                {
                    isOpen = false;
                    Close();
                }
                throw;
            }
        }
Esempio n. 16
0
 public static void LogCommand(DBCmd cmd, string text)
 {
     WriteLine(string.Format("Executing command {0} with text ='{1}'", cmd, text));
 }
Esempio n. 17
0
		public CommandResult Send( DBCmd cmd, byte[] bytes )
		{
//			string s = Encoding.GetString( bytes );

			Packet packet = CreatePacket(null);
			packetSeq = 0;
			packet.WriteByte( (byte)cmd );
			if (bytes != null)
				packet.Write( bytes, 0, bytes.Length );

			SendPacket( packet );
			packet = ReadPacket();

			// first check to see if this is a LOAD DATA LOCAL callback
			// if so, send the file and then read the results
			long fieldcount = packet.ReadLenInteger();
			if (fieldcount == Packet.NULL_LEN)
			{
				string filename = packet.ReadString();
				SendFileToServer( filename );
				packet = ReadPacket();
			}
			else
				packet.Position = 0;

			return new CommandResult(packet, this);
		}
Esempio n. 18
0
		/// <summary>
		/// Sends the specified command to the database
		/// </summary>
		/// <param name="command">Command to execute</param>
		/// <param name="text">Text attribute of command</param>
		/// <returns>Result packet returned from database server</returns>
		public void Send( DBCmd command, String text ) 
		{
			CommandResult result = Send( command, this.Encoding.GetBytes( text ) );
			if (result.IsResultSet)
				throw new MySqlException("SendCommand failed for command " + text );
		}
Esempio n. 19
0
 private void ExecuteCommand(DBCmd cmd, byte[] bytes, int length)
 {
     try
     {
         this.stream.StartOutput((ulong) (length + 1L), true);
         this.stream.WriteByte((byte) cmd);
         if (length > 0)
         {
             this.stream.Write(bytes, 0, length);
         }
         this.stream.Flush();
     }
     catch (MySqlException exception)
     {
         if (exception.IsFatal)
         {
             base.isOpen = false;
             this.Close();
         }
         throw;
     }
 }