Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

edu.virtualschool.jwaa.dbms.DBUtil Class Reference

List of all members.

Detailed Description

SQL Utilities Copyright 2002 by Brad Cox: <bcox@virtualschool.edu>

Definition at line 11 of file DBUtil.java.

Static Public Member Functions

final String quote (final Object o)
final String asSQLSet (Object[] list)
final String asSQLSet (Collection list)


Member Function Documentation

final String edu.virtualschool.jwaa.dbms.DBUtil.asSQLSet Collection  list  )  [static]
 

Converted the provided array to the quote-enclosed, comma-separate format required by mysql set or enum commands.

Parameters:
list: arguments to convert
Returns:
String

Definition at line 59 of file DBUtil.java.

00060   {
00061     StringBuffer buf = new StringBuffer();
00062     for (Iterator it = list.iterator(); it.hasNext();)
00063       buf.append("'" + it.next() + "'" + (it.hasNext() ? "," : ""));
00064     return buf.toString();
00065   }

final String edu.virtualschool.jwaa.dbms.DBUtil.asSQLSet Object[]  list  )  [static]
 

Converted the provided array to the quote-enclosed, comma-separate format required by mysql set or enum commands.

Definition at line 44 of file DBUtil.java.

00045   {
00046     int l = list.length;
00047     StringBuffer buf = new StringBuffer();
00048     for (int i = 0; i < l; i++)
00049       buf.append("'" + list[i] + "'" + (i < l - 1 ? "," : ""));
00050     return buf.toString();
00051   }

final String edu.virtualschool.jwaa.dbms.DBUtil.quote final Object  o  )  [static]
 

Quote string according to MySQL conventions, to block one easy attack

Definition at line 18 of file DBUtil.java.

00019   {
00020     if (o == null)
00021       return "\"null\"";
00022     final String s = o.toString();
00023     int n = 0;
00024     for (int i = 0; i < s.length(); i++)
00025       if (s.charAt(i) == '"')
00026         n++;
00027     if (n == 0)
00028       return "\"" + s + "\"";
00029 
00030     StringBuffer buf = new StringBuffer(s.length() + n);
00031     for (int i = 0; i < s.length(); i++)
00032     {
00033       if (s.charAt(i) == '"')
00034         buf.append("\\\"");
00035       else
00036         buf.append(s.charAt(i));
00037     }
00038     return buf.toString();
00039   }


The documentation for this class was generated from the following file: