Added a predefined format for MySQL (SANDBOX-410)
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1297944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4f3ef66ce3
commit
60709c2040
|
@ -66,6 +66,16 @@ public class CSVFormat implements Cloneable, Serializable {
|
|||
|
||||
/** Tabulation delimited format. */
|
||||
public static final CSVFormat TDF = new CSVFormat('\t', '"', DISABLED, DISABLED, true, true, false, true);
|
||||
|
||||
/**
|
||||
* Default MySQL format used by the <tt>SELECT INTO OUTFILE</tt> and
|
||||
* <tt>LOAD DATA INFILE</tt> operations. This is a tabulation delimited
|
||||
* format with a LF character as the line separator. Values are not quoted
|
||||
* and special characters are escaped with '\'.
|
||||
*
|
||||
* @see <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
|
||||
*/
|
||||
public static final CSVFormat MYSQL = new CSVFormat('\t', DISABLED, DISABLED, '\\', false, false, false, false).withLineSeparator("\n");
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -125,26 +125,20 @@ public class CSVPrinterTest extends TestCase {
|
|||
|
||||
public void testRandom() throws Exception {
|
||||
int iter = 10000;
|
||||
format = CSVFormat.DEFAULT;
|
||||
doRandom(iter);
|
||||
format = CSVFormat.EXCEL;
|
||||
doRandom(iter);
|
||||
|
||||
// Format for MySQL
|
||||
format = new CSVFormat('\t', CSVFormat.DISABLED, CSVFormat.DISABLED, '\\', false, false, false, false);
|
||||
doRandom(iter);
|
||||
doRandom(CSVFormat.DEFAULT, iter);
|
||||
doRandom(CSVFormat.EXCEL, iter);
|
||||
doRandom(CSVFormat.MYSQL, iter);
|
||||
}
|
||||
|
||||
Random r = new Random();
|
||||
CSVFormat format;
|
||||
|
||||
public void doRandom(int iter) throws Exception {
|
||||
public void doRandom(CSVFormat format, int iter) throws Exception {
|
||||
for (int i = 0; i < iter; i++) {
|
||||
doOneRandom();
|
||||
doOneRandom(format);
|
||||
}
|
||||
}
|
||||
|
||||
public void doOneRandom() throws Exception {
|
||||
public void doOneRandom(CSVFormat format) throws Exception {
|
||||
Random r = new Random();
|
||||
|
||||
int nLines = r.nextInt(4) + 1;
|
||||
int nCol = r.nextInt(3) + 1;
|
||||
// nLines=1;nCol=2;
|
||||
|
@ -215,6 +209,8 @@ public class CSVPrinterTest extends TestCase {
|
|||
}
|
||||
|
||||
public String randStr() {
|
||||
Random r = new Random();
|
||||
|
||||
int sz = r.nextInt(20);
|
||||
// sz = r.nextInt(3);
|
||||
char[] buf = new char[sz];
|
||||
|
|
Loading…
Reference in New Issue