Exemplo n.º 1
0
        private static void StartSql()
        {
            string dbName = Regex.Replace(dataDirectory, "\\S+\\\\", string.Empty);
            Ddl    ddl    = new Ddl();
            Dml    dml    = new Dml();

            using (SqlConnection sqlConnection
                       = !File.Exists(dataDirectory + ".mdf")
                ? ddl.CreateDatabase(dataDirectory, dbName, dataSource, integratedSecurity)
                : new SqlConnection($"Data Source={dataSource};" +
                                    $"AttachDbFilename={dataDirectory + ".mdf"};" +
                                    $"Integrated Security={integratedSecurity}"))
            {
                //Opens the sql connection
                OpenConnection(sqlConnection);
                //Reads and prints the table's date
                dml.SelectRows(sqlConnection, dataDirectory, dbName, Resource.SelectEmployees.ToString(), false);
                Console.WriteLine("\nTable of Grand Total\n");
                dml.SelectRows(sqlConnection, dataDirectory, dbName, Resource.GrandTotal.ToString(), true);
                Console.WriteLine("\nSorts by Job Title and Monthly Salary\n");
                dml.SelectRows(sqlConnection, dataDirectory, dbName, Resource.SortJobTitleMonthlySalary.ToString(), false);
                Console.WriteLine("\nSorts by Job Title and Total Compensation\n");
                dml.SelectRows(sqlConnection, dataDirectory, dbName, Resource.SortJobTitleTotalCompensation.ToString(), false);
                //Closes the connection
                sqlConnection.Close();
            }
            Console.WriteLine("\nPress <ENTER> to quit...");
            Console.ReadKey();
        }
Exemplo n.º 2
0
            private static bool IsFunctionName(string tok)
            {
                char begin        = tok[0];
                bool isIdentifier = char.IsLetter(begin) || begin.CompareTo('$') == 0 || begin.CompareTo('_') == 0 || '"' == begin;

                return(isIdentifier && !Formatter.Logical.Contains(tok) && !EndClauses.Contains(tok) && !Quantifiers.Contains(tok) &&
                       !Dml.Contains(tok) && !Formatter.Misc.Contains(tok));
            }
Exemplo n.º 3
0
        public void CreateTable(SqlConnection sqlConnection, string dbName)
        {
            Dml dml = new Dml();

            dbName = Regex.Replace(dbName, "\\S+\\\\", string.Empty);
            try
            {
                using (SqlCommand cmd = new SqlCommand($"USE {dbName}\n"
                                                       + Resource.VeneracionDatabase.ToString(), sqlConnection))
                {
                    cmd.ExecuteNonQuery();
                }
                //Inserts values in the Table
                dml.InsertRows(sqlConnection);
            }
            catch (IOException ex)
            {
                Console.WriteLine($"Missing File Error: {ex}");
            }
            catch (SqlException ex)
            {
                Console.WriteLine($"Creating Table Error: {ex}");
            }
        }
Exemplo n.º 4
0
            public string Perform()
            {
                _result.Append(Initial);

                while (_tokens.MoveNext())
                {
                    _token   = _tokens.Current;
                    _lcToken = _token.ToLowerInvariant();

                    if ("'".Equals(_token))
                    {
                        ExtractStringEnclosedBy("'");
                    }
                    else if ("\"".Equals(_token))
                    {
                        ExtractStringEnclosedBy("\"");
                    }

                    if (IsMultiQueryDelimiter(_token))
                    {
                        StartingNewQuery();
                    }
                    else if (_afterByOrSetOrFromOrSelect && ",".Equals(_token))
                    {
                        CommaAfterByOrFromOrSelect();
                    }
                    else if (_afterOn && ",".Equals(_token))
                    {
                        CommaAfterOn();
                    }
                    else if ("(".Equals(_token))
                    {
                        OpenParen();
                    }
                    else if (")".Equals(_token))
                    {
                        CloseParen();
                    }
                    else if (BeginClauses.Contains(_lcToken))
                    {
                        BeginNewClause();
                    }
                    else if (EndClauses.Contains(_lcToken))
                    {
                        EndNewClause();
                    }
                    else if ("select".Equals(_lcToken))
                    {
                        Select();
                    }
                    else if (Dml.Contains(_lcToken))
                    {
                        UpdateOrInsertOrDelete();
                    }
                    else if ("values".Equals(_lcToken))
                    {
                        Values();
                    }
                    else if ("on".Equals(_lcToken))
                    {
                        On();
                    }
                    else if (_afterBetween && _lcToken.Equals("and"))
                    {
                        Misc();
                        _afterBetween = false;
                    }
                    else if (Formatter.Logical.Contains(_lcToken))
                    {
                        Logical();
                    }
                    else if (IsWhitespace(_token))
                    {
                        White();
                    }
                    else
                    {
                        Misc();
                    }

                    if (!IsWhitespace(_token))
                    {
                        _lastToken = _lcToken;
                    }
                }
                return(_result.ToString());
            }