title: GDataDB: Concurrent connections & Google Docs
body: <p>I use GDataDB as online INI file to save user's settings on "clouds". I use single spreadsheet like below:</p>
  
  <pre><code> username   create     update       expire          amount
   3600001    20120303   20120303     20180303        9
   3600001    20120303   20120303     20160303        9
   3600020    20120301   20120303     20190505        14
  </code></pre>
  
  <p>I wonder what happens at concurrent writes/updates. I mean is it safe? What do you think?</p>
  
  <p>Here are the codes: As you see it's a low chance to access the file at the same time but I ask for future reference, to see it can be used or not on heavy -not to much- read-write operations. Or can I implement a lock mechanism?</p>
  
  <pre><code>        public class License
          {
              public string username { get; set; }
              public string create { get; set; }
              public string update { get; set; }
              public string expire { get; set; }
              public double amount { get; set; }
          }
  
  
  
          private static void Main(string[] args) {
  
  
              string myaccount = "xxxxxxxxxx@gmail.com";
              string mypass = "xxxxxxxxxxxxxxxx";
              string spreadsheet = "licence";
  
              string username = "03600001";
              double amount = 9.0d; //bucks
              int extend = 1; //year
  
              // create the DatabaseClient passing my Gmail or Google Apps credentials
              IDatabaseClient client = new DatabaseClient(myaccount, mypass);
  
              // get or create the database. This is the spreadsheet file 
              IDatabase db = client.GetDatabase(spreadsheet) ?? client.CreateDatabase(spreadsheet);
  
              // get or create the table. This is a worksheet in the file 
              // note I am using my Person object so it knows what my schema needs to be  
              // for my data. It will create a header row with the property names 
              ITable&lt;License&gt; table = db.GetTable&lt;License&gt;(spreadsheet) ?? db.CreateTable&lt;License&gt;(spreadsheet);
  
  
  
  
              var license = new License();
  
  
              IList&lt;IRow&lt;License&gt;&gt; rows = table.FindStructured(String.Format("username={0}", username)).OrderByDescending(o =&gt; o.Element.expire).Take(1).ToList();
  
              if (rows == null || rows.Count == 0)
              {
                  //add new
                  license.username = username;
                  license.create = DateTime.Now.ToString("yyyyMMdd");
                  license.update = license.create;
                  license.expire = DateTime.Now.AddYears(extend).ToString("yyyyMMdd");
                  license.amount = amount;
  
                  table.Add(license);
              }
              else
              {
                  //update
                  IRow&lt;License&gt; row = rows[0];
  
                  DateTime expire = DateTime.ParseExact(row.Element.expire, "yyyyMMdd", null);
  
                  row.Element.expire = expire.AddYears(extend).ToString("yyyyMMdd");
                  row.Element.update = DateTime.Now.ToString("yyyyMMdd");
                  row.Element.amount = amount;
  
                  row.Update();
              }
  
            }
  </code></pre>