internal void RunCommands(SqlCeCmd.Program.Options options) { using (var sr = new SqlCommandReader(options.QueryFile)) { var commandText = sr.ReadCommand(); while (!string.IsNullOrWhiteSpace(commandText)) { if (!options.HideOutput) { Console.WriteLine("Executing: " + commandText); } options.QueryText = commandText; RunCommand(options); commandText = sr.ReadCommand(); } } }
internal void RunCommand(SqlCeCmd.Program.Options options) { using (SqlCeCommand cmd = new SqlCeCommand()) { int n = 0; cmd.CommandText = Regex.Replace(options.QueryText, @"SqlCeCmd_LoadImage\((\w+\.\w+)\)", delegate(Match m) { string id = m.Groups[1].Value; string paramName = string.Format(CultureInfo.InvariantCulture, "@SqlCeCmd_IMAGE_{0}", n++); string fileName = Path.Combine(Directory.GetCurrentDirectory(), id);; if (!string.IsNullOrEmpty(options.QueryFile)) { fileName = Path.Combine(Path.GetDirectoryName(options.QueryFile), id); } using (BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open))) { byte[] data = br.ReadBytes((int)br.BaseStream.Length); SqlCeParameter parameter = new SqlCeParameter(paramName, System.Data.SqlDbType.Image, data.Length); parameter.Value = data; cmd.Parameters.Add(parameter); } return(paramName); }); if (options.UseCurrentCulture) { this.cultureInfo = System.Globalization.CultureInfo.CurrentCulture; } if (options.Headers == 0) { this.writeHeaders = false; } if (options.Headers > 0) { this.headerInterval = options.Headers; } if (options.MakeXML) { this.xmlOutput = true; } int rows = 0; CommandExecute execute = FindExecuteType(options.QueryText); if (execute != CommandExecute.Undefined) { if (execute == CommandExecute.DataReader) { if (this.xmlOutput) { rows = RunDataTable(cmd, conn); } else { rows = RunDataReader(cmd, conn, options.ColumnSeparator, options.RemoveSpaces); if (!options.HideOutput) { Console.WriteLine(); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "({0} rows affected)", rows.ToString(cultureInfo))); } } } if (execute == CommandExecute.NonQuery) { rows = RunNonQuery(cmd, conn); if (!options.HideOutput) { Console.WriteLine(); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "({0} rows affected)", rows.ToString(cultureInfo))); } } if (execute == CommandExecute.Insert) { rows = RunNonQuery(cmd, conn); } } } }