В зависимости от Вашего варианта использования можно также хотеть проверить csv модуль:
import csv
lines = ['this is "a string"', 'and more "stuff"']
for row in csv.reader(lines, delimiter=" "):
print row
Вывод:
['this', 'is', 'a string']
['and', 'more', 'stuff']
No, I don't think that SqlBulkCopy
is supported (see MSDN). Perhaps throw the data in as xml and strip it apart at the server? SQL/XML is pretty good in 2005/2008.
You might also want to look at table-value-parameters, but I doubt that CE supports these.
BULKCOPY не поддерживается в SQL CE. Вот самый быстрый способ, если в вашей таблице огромное количество строк; вставка выполняется слишком медленно!
using (SqlCeConnection cn = new SqlCeConnection(yourConnectionString))
{
if (cn.State == ConnectionState.Closed)
cn.Open();
using (SqlCeCommand cmd = new SqlCeCommand())
{
cmd.Connection = cn;
cmd.CommandText = "YourTableName";
cmd.CommandType = CommandType.TableDirect;
using (SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable))
{
SqlCeUpdatableRecord record = rs.CreateRecord();
using (var sr = new System.IO.StreamReader(yourTextFilePath))
{
string line;
while ((line = sr.ReadLine()) != null)
{
int index = 0;
string[] values = line.Split('\t');
//write these lines as many times as the number of columns in the table...
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
record.SetValue(index, values[index++] == "NULL" ? null : values[index - 1]);
rs.Insert(record);
}
}
}
}
}
Тест: таблица с 34370 строками
со вставками: 38 строк, записываемых в секунду
таким образом: 260 строк, записываемых в секунду