ラベル Azure の投稿を表示しています。 すべての投稿を表示
ラベル Azure の投稿を表示しています。 すべての投稿を表示

2014年5月2日金曜日

SSMS経由でExcelデータをAzure SQLへインポート

2つテクニックがあります。
1)データインポートのメニューを出すために、ローカルDBに接続し、そのDBの名前を右クリックすると、「タスク→データのインポート」選択できる。その後、変換先のサーバー名をAzure SQLを指定すれば良い。

2)Azure SQLのテーブルには、[id]列は必須です。「マッピングの編集→SQLの編集」で
「[id] int identity primary key,」を追加。


詳細な操作は下記ビデオをご覧ください。

http://www.youtube.com/watch?v=QAd2uAGNHPw

2014年4月11日金曜日

Azure sql server上保存された場所を現在地からの距離順で表示

Azure sql serverのtableに場所名とその位置情報を保存している。
現在地からの距離順で場所を表示させる方法。

Azure mobile serviceのtableスクリプトを利用する。
読み取り操作に、以下のスクリプトを入れる。
requestのパラメータとして、現在地の経度と緯度をserver scriptに渡す。
SHOPINFOのGPSLOC列から位置情報を取り出し、距離を計算する。

function read(query, user, request) {
    var lat = request.parameters.lat;
    var lng = request.parameters.lng;
    var sql = "DECLARE @g geography;"+
              "SET @g = geography::Point(?,?, 4326);"+
              "SELECT *,round(@g.STDistance(GPSLOC),0) as DIST from [dbo].SHOPINFO order by DIST;"
    mssql.query(sql,[lat,lng],{success: function(results) {
        request.respond(200,results);
    }
    })
}

アプリから、get methodで以下のURLにアクセスする。
https://abcdef.azure-mobile.net/tables/shopinfo?lat=latitudeFromGps&lng=longitudeFromGps


参考になったページ:http://hatsune.hatenablog.jp/entry/2014/02/06/092155

2014年2月25日火曜日

既存のAzure上テーブルをmobile serviceにリンクさせる

Azureのsql server管理ポータルでmobile serviceと同じ名前のキスーマに追加し、編集してあるテーブルをmobile serviceにリンクさせるには、mobile serviceのDATAタブの「CRAETE」をクリックし、既存のテーブル名を指定するだけで、リンクできる。

以下のURLには、もっと詳しい情報がある。
http://blogs.msdn.com/b/jpsanders/archive/2013/05/24/using-an-existing-azure-sql-table-with-windows-azure-mobile-services.aspx

2014年2月24日月曜日

sql serverにおける位置情報の保存

Azure mobile serviceのDBはsql serverとなっている。アプリで位置情報を扱うため、その保存方法を調べてみた。以下の文章に、3つが書かれている。
http://www.sql-server-helper.com/sql-server-2008/convert-latitude-longitude-to-geography-point.aspx


  • 方法1、STPointFromTextを使用

ALTER TABLE [dbo].[Landmark]
ADD [GeoLocation] GEOGRAPHY
GO

UPDATE [dbo].[Landmark]
SET [GeoLocation] = geography::STPointFromText('POINT(' + CAST([Longitude] AS VARCHAR(20)) + ' ' + CAST([Latitude] AS VARCHAR(20)) + ')', 4326)
GO

ここは、経度Latitudeより緯度Longitudeが先に来ている。


  • 方法2、STGeomFromTextを使用

UPDATE [dbo].[Landmark]
SET [GeoLocation] = geography::STGeomFromText('POINT(' + CAST([Longitude] AS VARCHAR(20)) + ' ' + CAST([Latitude] AS VARCHAR(20)) + ')', 4326)
GO

STGeomFromText は、POINT以外 POLYGON, LINESTRING, MULTIPOINT, MULTIPOLYGON, MULTILINESTRING and GEOMETRYCOLLECTIONもサポートしている。


  • 方法3、geography::Pointを使用

UPDATE [dbo].[Landmark]
SET [GeoLocation] = geography::Point([Latitude], [Longitude], 4326)
GO

ここは、経度Latitudeが先で、一番使いやすいと思う。


  • 方法4、geography::Parseを使用

UPDATE [dbo].[Landmark]
SET [GeoLocation] = geography::Parse('POINT(' + CAST([Longitude] AS VARCHAR(20)) + ' ' +
                    CAST([Latitude] AS VARCHAR(20)) + ')')
GO

geography::STGeomFromText と唯一の違いは、spatial reference ID (SRID) 4326の指定は不要。

2013年10月13日日曜日

Azure SQLのデータをListViewに表示させる


public class MainActivity extends Activity {

MobileServiceClient mClient;
MobileServiceTable<TokutenItem> mTokutenTable;
TokutenItemAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.benefit_list);
// 1)ListViewとadapterを設定、rowのlayoutも紐づく
mAdapter = new TokutenItemAdapter(this, R.layout.benifit_cell);
ListView listViewBenefit = (ListView) findViewById(R.id.benefitList);
listViewBenefit.setAdapter(mAdapter);

try {
// 2)Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
        "https://xxxxxxx.azure-mobile.net/",
"keyforAzuraMobileService"
this);

// 3)Get the Mobile Service Table instance to use
mTokutenTable = mClient.getTable(TokutenItem.class);
} catch (MalformedURLException e) {
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
// 4)SQL実行
mTokutenTable.where().field("venusId").eq("4e25173e091a817e3dd67300")
.execute(new TableQueryCallback<TokutenItem>() {
                          // 5)SQL完了したあとのcallbackでadapterを更新
public void onCompleted(List<TokutenItem> result, 
        int count,
                Exception exception, 
                ServiceFilterResponse response) {   
   if (exception == null) {
mAdapter.clear();
        for (TokutenItem item : result) {
mAdapter.add(item);
}

   } else {
        createAndShowDialog(exception, "Error");
  }
        }
});
}

Adapterの設計

public class TokutenItemAdapter extends ArrayAdapter<TokutenItem>{
/**
* Adapter context
*/
Context mContext;

/**
* Adapter View layout
*/
int mLayoutResourceId;

public TokutenItemAdapter(Context context, int layoutResourceId) {
super(context, layoutResourceId);

mContext = context;
mLayoutResourceId = layoutResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;

final TokutenItem currentItem = getItem(position);

if (row == null) {//再利用できるrowがあるかどうかをチェック、なければ新規作成
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
row = inflater.inflate(mLayoutResourceId, parent, false);
}

//rowのlayoutになにを表示させるかを設定
TextView pointTv = (TextView) row.findViewById(R.id.point);
TextView priceDownTv = (TextView) row.findViewById(R.id.priceDown);
pointTv.setText(Float.toString(currentItem.getPointUp()));
priceDownTv.setText(Integer.toString(currentItem.getPriceDown()));
return row;
}

}

2013年9月20日金曜日

AndroidにおけるAzureの使用、SQLにinsert

AndroidからAzureのSQLを使用には、簡単です。

1)Tableの構造と合うclassを用意します。

package com.example.azuretest;

public class TokutenItem {
@com.google.gson.annotations.SerializedName("id")
private int mId;
@com.google.gson.annotations.SerializedName("venusId")
private String mVenusId;

@com.google.gson.annotations.SerializedName("pointUp")
private  float mPointUp;
@com.google.gson.annotations.SerializedName("pricedown")
private int mPriceDown;
@com.google.gson.annotations.SerializedName("cardId")
private int mCardId;
public TokutenItem(String venusId, float pointUp, int priceDown, int cardId) {
//this.setId(id); idは自動的に付与され、set不可のようです
this.setVenusId(venusId);
this.setPointUp(pointUp);
this.setPriceDown(priceDown);
this.setCardId(cardId);
}
public int getId() {
return mId;
}
public String getVenusId() {
return mVenusId;
}
public float getPointUp() {
return mPointUp;
}
public int getPriceDown() {
return mPriceDown;
}
public int getCardId() {
return mCardId;
}
public final void setId(int id) {
mId = id;
}
public final void setVenusId(String venusId) {
mVenusId = venusId;
}
public final void setPointUp(float pointUp) {
mPointUp = pointUp;
}
public final void setPriceDown(int priceDown) {
mPriceDown = priceDown;
}
public final void setCardId(int cardId) {
mCardId = cardId;
}
}

2)MobileServiveClientの設定、そしてMobileServiceTableの設定

try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"https://xxxxxxx.azure-mobile.net/",
"keyforAzuraMobileService"
this);

// Get the Mobile Service Table instance to use
mTokutenTable = mClient.getTable(TokutenItem.class);
     } catch (MalformedURLException e) {
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
       }
        // 挿入したいItem項目をclassに入れる、idの設定は不可
TokutenItem mTokutenItem = new TokutenItem("4e25173e091a817e3dd67300",2,300,3);
mTokutenTable.insert(mTokutenItem, new TableOperationCallback<TokutenItem>() {
        public void onCompleted(TokutenItem entity, 
                Exception exception, 
                ServiceFilterResponse response) {   
           if (exception == null) {
        //Log.i(TAG, "Read object with ID " + entity.id);
           } else {
        createAndShowDialog(exception, "Error");
           }
        }
});

getTableは、classの構造に合わせて、SQLの列を追加してくれます。

3) Permissionの追加を忘れず
<uses-permission android:name="android.permission.INTERNET" />

2013年9月13日金曜日

Azureプレミアクーポン券をいただいた

日本MS本社に、あるセミナーに参加しに行ったら、何と454,500円分のAzureプレミアクーポンをいただきました。これはありがたいです。ますます、Azureに傾くようになりました。MSさんはクラウド分野で、一生懸命追いついていますね。

2013年9月6日金曜日

AWSのセミナーに参加しました

AWSのサービスメニューが多すぎ、わけが分からなくなります。公開セミナーに参加しました。セミナーの内容を聞いても、サービスの全体図はよくわかりません。
サーバー構築・管理の基礎知識のない私にとって、AWSのハードルが高いです。

分かりやすいWindows Azureを使って、頑張っていきます。

2013年8月30日金曜日

Azure資料

初めてAzureのモバイルサービスを使いたくて、日本語のチュートリアルを見ながら実行してみました。

http://www.windowsazure.com/ja-jp/develop/mobile/tutorials/get-started-with-data-android/

とりあえず動きましたが、APIの使いたいの説明は一切ないため、もの足りません。

英語のDocumentationを探さなければいけないかなと思って、やはりありました。

http://www.windowsazure.com/en-us/develop/mobile/how-to-guides/work-with-android-client-library/

2013年8月27日火曜日

MSから電話が入りました

先日Windows Azureの無料評価版に登録して、いろいろ試してみました。
今日はアメリカ番号の電話が入りました。あやしいなあと思ったが、でました。
日本の方は日本語で、「MSの人ですが、Azureにつてフォローしています。」といった趣旨の電話でした。

AWSにも登録しましたが、このような電話フォローはありません。
MSはクラウドでは追いつく立場でしょうか、その懸命さが伝わってきました。

分かりやすさについて、個人的にはAzureのほうがAWSより理解しやすいと思っています。

2013年8月24日土曜日

Windows Azure SDKのインストール


アプリのデータをクラウドから取るには、Windows Azureを1つの候補として検討しています。

MAC用azureコマンドラインツールを使うには、以下のリンクにて、Windows Azure SDKをインストル必要はあります。

https://www.windowsazure.com/ja-jp/develop/nodejs/how-to-guides/command-line-tools/