應用程序有沒有用戶輸入的,也不會是活在網絡上,所以SQL注入是不是威脅如何更新多個SQL行,其中表1的ID等於表2的ID
我的應用程序
此應用程序應該從1個表格向Google地理編碼器API發送多個地址,並將返回的緯度和經度存儲在第二個表格中供以後使用。API每天最多可以處理2500個請求。
問題是什麼
當我運行我的程序,沒有limmits,只有幾排(約20),獲得更新出來,都應該得到更新2500行。當我限制我的程序只更新10行以避免觸及API限制時,不會發生任何更改。我允許2500次請求時更新的大部分行都使用正確的值進行更新(除了少數幾個之外),現在我不擔心這一點,我認爲這只是地理編碼器的糟糕結果。
我有什麼到目前爲止
我有2串strLat和strLong持有從谷歌地理編碼API檢索lattitudes和經度。
string strLat = myCoordenates.Results[3].Geometry.Location.Lat.ToString();
string strLong = myCoordenates.Results[3].Geometry.Location.Lng.ToString();
我也有我的企圖用他們更新我的數據庫。這已經改變和操縱很多次了,我認爲這個問題很可能與我的這部分代碼有關。
using (SqlConnection myConnection = new SqlConnection(context))
{
myConnection.Open();
string strQueryUpdate = "UPDATE WEB_ARENA_GEO SET Lat = '" + strLat + "', Lng = '" + strLong + "'" + "WHERE ARENA_ID='" + row.ARENA_ID + "'";
SqlCommand myCommandUpdate = new SqlCommand(strQueryUpdate, myConnection);
myCommandUpdate.ExecuteNonQuery();
}
以我數據的基礎上表1保持地址數據它具有PK ID以及一個稱爲ADDRESS_ID列,然後地址被分解等地址,城市,ST,ZIP ... ETC,表2持有緯度和經度,並且具有相同的等值的同一個ADDRESS_ID表,目前大部分的lats和lng都是0.00,它是十進制的。
表1
| --PKid-- | ADDRESS_ID |地址| CITY ..等
| 124246 | 70-00002913 | 112 bill st。 |鮑勃鎮
表2
| ADDRESS_ID | Lat | Lng |
| 70-00002913 | 0.00 | 0.00 |
整個更新控制器
//GET: /TABLE2/Update/
public ActionResult Update(string id)
{
IEnumerable<TABLE1> table1 = db.TABLE1;
IEnumerable<TABLE2> table2 = db.TABLE2;
string context = "my database context here";
foreach (var row in table1.AsEnumerable().Take(10))
{
string strAddr = row.ADDRESS + "," + row.CITY + "," + row.ZIP + "," + row.COUNTRY;
GoogleMapsDll.GeoResponse myCoordenates = new GoogleMapsDll.GeoResponse();
myCoordenates = GoogleMapsDll.GoogleMaps.GetGeoCodedResults(strAddr);
if (myCoordenates.Results != null && myCoordenates.Results.Length > 3)
{
string strLat = myCoordenates.Results[3].Geometry.Location.Lat.ToString();
string strLong = myCoordenates.Results[3].Geometry.Location.Lng.ToString();
using (SqlConnection myConnection = new SqlConnection(context))
{
myConnection.Open();
string strQueryUpdate = "UPDATE WEB_ARENA_GEO SET Lat = '" + strLat + "', Lng = '" + strLong + "'" + "WHERE ADDRESS_ID='" + row.ADDRESS_ID + "'";
SqlCommand myCommandUpdate = new SqlCommand(strQueryUpdate, myConnection);
myCommandUpdate.ExecuteNonQuery();
}
db.SaveChanges();
}
}
return RedirectToAction("Index");
如果任何其他信息將是有益的,請簡單地問了意見,我會盡我所能提供
我不是其所以然清楚,你不知道該怎麼在這裏做?它在UPDATE中使用JOIN嗎? – 2014-12-04 14:32:56
你好SQL注入 – 2014-12-04 14:33:28
我需要能夠更新表2中的行與正確的緯度和經度與表1中相同的ID相匹配 – RyeNyeTheComputerScienceGuy 2014-12-04 14:34:18