Java String Split splitSQL(List list, String sql)

Here you can find the source of splitSQL(List list, String sql)

Description

split SQL

License

Open Source License

Declaration

static void splitSQL(List<String> list, String sql) 

Method Source Code


//package com.java2s;

import java.util.List;

public class Main {
    static void splitSQL(List<String> list, String sql) {
        int idx = 0;
        int start = 0;
        boolean isVar = false;
        while (idx < sql.length()) {
            char c = sql.charAt(idx);
            if (c == '@') {
                if (idx > start) {
                    list.add(sql.substring(start, idx));
                }//  w  w w  .j a va 2s.c  om
                start = idx;
                isVar = true;
            } else if (isVar && !isValidName(c)) {
                if (idx > start) {
                    list.add(sql.substring(start, idx));
                }
                start = idx;
                isVar = false;
            }
            idx++;
        }
        if (start < sql.length()) {
            list.add(sql.substring(start));
        }
    }

    private static boolean isValidName(char c) {
        switch (c) {
        case '.':
        case '_':
        case '?':
            return true;
        default:
            return Character.isLetterOrDigit(c);
        }
    }
}

Related

  1. splitSelectionAsInteger(String selection)
  2. splitSemicolonString(String semicolonString)
  3. splitSentence(String sentence)
  4. splitSimple(String split, String s)
  5. splitSimpleQueries(String queryString)
  6. splitSQLColumns(String sql)
  7. splitStep(String step)
  8. splitStr(String str, int toCount)
  9. splitString(String bigString, String splitter)