Ejemplo n.º 1
0
        // We try parsing the SQL statement to get the table name as a last resort when
        // the driver doesn't return this information back to us.
        //
        // we can't handle multiple tablenames (JOIN)
        // only the first tablename will be returned

        internal string GetTableNameFromCommandText()
        {
            if (command == null){
                return null;
            }
            String localcmdtext = _cmdText;
            if (ADP.IsEmpty(localcmdtext)) { // fxcop
                return null;
            }
            String tablename;
            int     idx;
            CStringTokenizer tokenstmt = new CStringTokenizer(localcmdtext, Connection.QuoteChar(ADP.GetSchemaTable)[0], Connection.EscapeChar(ADP.GetSchemaTable));

            if (tokenstmt.StartsWith("select") == true) {
              // select command, search for from clause
              idx = tokenstmt.FindTokenIndex("from");
            }
            else {
                if ((tokenstmt.StartsWith("insert") == true) ||
                    (tokenstmt.StartsWith("update") == true) ||
                    (tokenstmt.StartsWith("delete") == true) ) {
                    // Get the following word
                    idx = tokenstmt.CurrentPosition;
                }
                else
                    idx = -1;
            }
            if (idx == -1)
                return null;
            // The next token is the table name
            tablename = tokenstmt.NextToken();

            localcmdtext = tokenstmt.NextToken();
            if ((localcmdtext.Length > 0) && (localcmdtext[0] == ',')) {
                return null;        // can't handle multiple tables
            }
            if ((localcmdtext.Length == 2) &&
                ((localcmdtext[0] == 'a') || (localcmdtext[0] == 'A')) &&
                ((localcmdtext[1] == 's') || (localcmdtext[1] == 'S'))) {
                // aliased table, skip the alias name
                localcmdtext = tokenstmt.NextToken();
                localcmdtext = tokenstmt.NextToken();
                if ((localcmdtext.Length > 0) && (localcmdtext[0] == ',')) {
                    return null;        // Multiple tables
                }
            }
            return tablename;
        }
 internal string GetTableNameFromCommandText()
 {
     int currentPosition;
     if (this.command == null)
     {
         return null;
     }
     string str = this._cmdText;
     if (ADP.IsEmpty(str))
     {
         return null;
     }
     CStringTokenizer tokenizer = new CStringTokenizer(str, this.Connection.QuoteChar("GetSchemaTable")[0], this.Connection.EscapeChar("GetSchemaTable"));
     if (tokenizer.StartsWith("select"))
     {
         currentPosition = tokenizer.FindTokenIndex("from");
     }
     else if ((tokenizer.StartsWith("insert") || tokenizer.StartsWith("update")) || tokenizer.StartsWith("delete"))
     {
         currentPosition = tokenizer.CurrentPosition;
     }
     else
     {
         currentPosition = -1;
     }
     if (currentPosition == -1)
     {
         return null;
     }
     string str2 = tokenizer.NextToken();
     str = tokenizer.NextToken();
     if ((str.Length > 0) && (str[0] == ','))
     {
         return null;
     }
     if ((str.Length == 2) && ((str[0] == 'a') || (str[0] == 'A')))
     {
         if ((str[1] != 's') && (str[1] != 'S'))
         {
             return str2;
         }
         str = tokenizer.NextToken();
         str = tokenizer.NextToken();
         if ((str.Length > 0) && (str[0] == ','))
         {
             return null;
         }
     }
     return str2;
 }