Android Open Source - sloop-sql Util






From Project

Back to project page sloop-sql.

License

The source code is released under:

SloopSQL is released into the Public Domain. There are no restrictions on how you may use this code, and there is no warranty or guarantee of fitness for anything. USE AT YOUR OWN RISK (and enjoy).

If you think the Android project sloop-sql listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.megginson.sloopsql;
/*from   w  ww  . jav  a2s .  c  o  m*/
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.content.Context;
import android.widget.Toast;
import java.util.List;
import java.util.ArrayList;

/**
 * Static utility methods for the application.
 */
public final class Util
{

  /**
   * Inflate a layout.
   *
   * @param context The context (e.g. activity) from which to grab an
   * inflater.
   * @param id The identifier of the XML layout to inflate.
   * @return The inflated view.
   */
  public static View inflate(Context context, int id)
  {
    LayoutInflater inflater = LayoutInflater.from(context);
    return inflater.inflate(id, null);
  }

  /**
   * Show a long toast pop-up message.
   *
   * @param context The context (e.g. activity) in which to show the toast.
   * @param message The string message to show.
   */
  public static void toast(Context context, String message)
  {
    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
  }

  /**
   * Construct a stacktrace string from a throwable.
   *
   * Combine all the {@link StackTrace} objects in a throwable into a
   * single string, for debugging.
   *
   * @param t The throwable from which to extract the stacktrace.
   * @return A representation of the stacktrace as a single string.
   */
  public static String makeStackTrace(Throwable t)
  {
    StringBuffer s = new StringBuffer(t.getMessage());
    for (StackTraceElement e : t.getStackTrace())
    {
      s.append('\n');
      s.append(e.toString());
    }
    return s.toString();
  }

  /**
   * Split a string into multiple SQL statements using ";" as a separator.
   */
  public static List<String> splitSQL(String statementsText)
  {
    List<String> statementList = new ArrayList<String>();
    StringBuffer statement = new StringBuffer();

    for (int i = 0; i < statementsText.length(); i++)
    {
      char c = statementsText.charAt(i);
      switch (c)
      {
        case ';':
          String s = statement.toString().trim();
          if (s.length() > 0)
          {
            statementList.add(s.toString());
            statement.setLength(0);
          }
          break;
        case '\'':
        case '"':
        case '`':
          statement.append(c);
          while (++i < statementsText.length())
          {
            char c1 = statementsText.charAt(i);
            statement.append(c1);
            if (c == c1)
            {
              break;
            }
          }
          break;
        default:
          statement.append(c);
          break;
      }
    }

    // straggler without a semicolon?
    String s = statement.toString().trim();
    if (s.length() > 0)
    {
      statementList.add(s);
    }

    return statementList;
  }

}




Java Source Code List

com.megginson.sloopsql.AsyncResult.java
com.megginson.sloopsql.CSVCursorSerializer.java
com.megginson.sloopsql.DatabaseHandler.java
com.megginson.sloopsql.MainActivity.java
com.megginson.sloopsql.QueryFragment.java
com.megginson.sloopsql.QueryResultAdapter.java
com.megginson.sloopsql.ScriptFragment.java
com.megginson.sloopsql.TabListener.java
com.megginson.sloopsql.TableListAdapter.java
com.megginson.sloopsql.TableListFragment.java
com.megginson.sloopsql.Util.java