/// <summary> /// Creates an instance of FbScript class. /// </summary> /// <param name="sqlFilename">The filename for the SQL file.</param> public FbScript(string sqlFilename) { string script = ""; StreamReader reader = null; try { reader = File.OpenText(sqlFilename); script = reader.ReadToEnd(); } catch { throw; } finally { if (reader != null) { reader.Close(); } } this.results = new StringCollection(); this.parser = new StringParser(RemoveComments(script), false); this.parser.Token = ";"; }
/// <summary> /// Creates an instance of FbScript class. /// </summary> /// <param name="sqlCode">A <see cref="TextReader"/> instance.</param> /// <remarks>The all data in <see cref="TextReader"/> is read.</remarks> public FbScript(TextReader sqlCode) { this.results = new StringCollection(); this.parser = new StringParser(RemoveComments(sqlCode.ReadToEnd()), false); this.parser.Token = ";"; }
/// <summary> /// Updates the connection string with the data parsed from the parameter and opens a connection /// to the database. /// </summary> /// <param name="connectDbStatement"></param> protected internal void ConnectToDatabase(string connectDbStatement) { // CONNECT 'filespec' [USER 'username'][PASSWORD 'password'] [CACHE int] [ROLE 'rolename'] StringParser parser = new StringParser(connectDbStatement, false); parser.Token = " "; parser.ParseNext(); if (parser.Result.Trim().ToUpper(CultureInfo.CurrentCulture) != "CONNECT") { throw new Exception("Malformed isql CONNECT statement. Expected keyword CONNECT but something else was found."); } parser.ParseNext(); this.connectionString.Database = parser.Result.Replace("'", ""); while (parser.ParseNext() != -1) { switch (parser.Result.Trim().ToUpper(CultureInfo.CurrentCulture)) { case "USER": parser.ParseNext(); this.connectionString.UserID = parser.Result.Replace("'", ""); break; case "PASSWORD": parser.ParseNext(); this.connectionString.Password = parser.Result.Replace("'", ""); break; case "CACHE": parser.ParseNext(); break; case "ROLE": parser.ParseNext(); this.connectionString.Role = parser.Result.Replace("'", ""); break; default: throw new Exception("Unexpected token '" + parser.Result.Trim() + "' on isql CONNECT statement."); } } this.requiresNewConnection = true; this.ProvideConnection(); }