I am synchronizing a huge database from it's oracle datasource to a mysql datasource for other purposes. When reading the data using PuTTY in a linux/oracle database the value is
我正在将一个巨大的数据库从它的oracle数据源同步到一个mysql数据源以用于其他目的。在linux / oracle数据库中使用PuTTY读取数据时,值为
8888888888
This is stored into an object and then inserted in MySQL and then ends up becoming
它存储在一个对象中,然后插入MySQL中,然后最终成为
00000000000000000000000000000000000000000000000000000000000000000000008888888888
Now I am unfortunately no programming hero and I can't seem to figure out the problem. The datatype in both databases is int(10) and the C# Application does no no way tamper with any values. Here is the actual error message: (omitted irrelevant parts of the statement)
现在我不幸没有编程英雄,我似乎无法弄清楚问题。两个数据库中的数据类型都是int(10),C#Application不会篡改任何值。这是实际的错误消息:(省略了语句的无关部分)
Error while executing query
INSERT INTO tsdsmd(kode8)
VALUES ('00000000000000000000000000000000000000000000000000000000000000000000008888888888')
Out of range value for column 'kode8' at row 1
Could it be a charset mismatch?
这可能是一个charset不匹配?
This is the code that builds the insert command
这是构建insert命令的代码
public int Insert(string table, string[] fields, object[] values)
{
if (fields.Length != values.Length)
throw new DBException("Field lengt is not equal to values length!");
StringBuilder query = new StringBuilder();
query.Append("INSERT INTO ");
query.Append(table);
query.Append("( ");
for (int i = 0; i < fields.Length; i++)
{
query.Append(fields[i]);
if (i != fields.Length - 1)
{
query.Append(", ");
}
}
query.Append(") VALUES (");
for (int i = 0; i < fields.Length; i++)
{
query.Append("@" + fields[i]);
if (i != fields.Length - 1)
{
query.Append(", ");
}
}
query.Append(")");
DBCommand command = new DBCommand(query.ToString());
for (int i = 0; i < fields.Length; i++)
{
command.AddParameter("@" + fields[i], values[i]);
}
return Insert(command);
}
Edit; I have changed some of the code and I am now skipping those rows for the while being with a separate try catch. Have a look and this is what I am seeing. The value shoudl be within the bounds of an int and I am so confused. Potential bug? The error it gives me that the int is too small or too large for an int32. Which should not be the case.
编辑;我已经改变了一些代码,现在我正在使用单独的try catch跳过这些行。看看,这就是我所看到的。值shoudl在int的范围内,我很困惑。潜在的错误?它给我的错误是int对于int32而言太小或太大。不应该是这种情况。
2 个解决方案
#1
1
This looks to me like you may need to explicitly cast the value when adding the parameter. The value your code is trying to insert is the wrong data type and zero-padded, but it's technically correct. It should fix the problem if you do this:
这看起来像你可能需要在添加参数时显式地转换值。您的代码尝试插入的值是错误的数据类型和零填充,但它在技术上是正确的。如果你这样做,它应该解决问题:
command.AddParameter("@" + fields[i], (int)values[i])
command.AddParameter(“@”+ fields [i],(int)values [i])
Admittedly, that will be a bit of a pain if you're trying to deal with multiple data types dynamically, but it shouldn't be too tough to add a few tests to figure the value's proper data type.
不可否认,如果您尝试动态处理多种数据类型,那将会有点痛苦,但是添加一些测试以确定值的正确数据类型应该不会太难。
#2
0
Actually, the column in oracle is not limited by int32 like "int" from mysql is. Will have to convert the mysql column to int64/long.
实际上,oracle中的列不受int32的限制,就像mysql中的“int”一样。将mysql列转换为int64 / long。
#1
1
This looks to me like you may need to explicitly cast the value when adding the parameter. The value your code is trying to insert is the wrong data type and zero-padded, but it's technically correct. It should fix the problem if you do this:
这看起来像你可能需要在添加参数时显式地转换值。您的代码尝试插入的值是错误的数据类型和零填充,但它在技术上是正确的。如果你这样做,它应该解决问题:
command.AddParameter("@" + fields[i], (int)values[i])
command.AddParameter(“@”+ fields [i],(int)values [i])
Admittedly, that will be a bit of a pain if you're trying to deal with multiple data types dynamically, but it shouldn't be too tough to add a few tests to figure the value's proper data type.
不可否认,如果您尝试动态处理多种数据类型,那将会有点痛苦,但是添加一些测试以确定值的正确数据类型应该不会太难。
#2
0
Actually, the column in oracle is not limited by int32 like "int" from mysql is. Will have to convert the mysql column to int64/long.
实际上,oracle中的列不受int32的限制,就像mysql中的“int”一样。将mysql列转换为int64 / long。