技术开发 频道

微软WP7本机数据库解决方案之Sqlite

  UriKind.Relative)).Stream;

  IsolatedStorageFileStream dest
=

  
new IsolatedStorageFileStream(dbName,

  System.IO.FileMode.OpenOrCreate,

  System.IO.FileAccess.Write, store);

  src.Position
= 0;

  CopyStream(src, dest);

  dest.Flush();

  dest.Close();

  src.Close();

  dest.Dispose();

  }

  
private static void CopyStream(System.IO.Stream input,

  IsolatedStorageFileStream output)

  {

  
byte[] buffer = new byte[32768];

  
long TempPos = input.Position;

  
int readCount;

  
do

  {

  readCount
= input.Read(buffer, 0, buffer.Length);

  
if (readCount > 0)

  {

  output.Write(buffer,
0, readCount);

  }

  }
while (readCount > 0);

  input.Position
= TempPos;

  }

  }

  }

  顺便说一句,对于上面这个帮助类我也没有提供细致的优化编码。希望读者根据您的相关工作能够继续进行这项工作(例如提供更好的泛型化的CRUD支持)并分享给广大网友。简言之,我主要是增加了插入和删除方法。上面的代码中最引起您注意是地方一定是方法CopyFromContentToStorage,正是借助这个方法我们实现了上述目标-建立起SQLite数据库与独立存储的关系。

  三、小结

  本文中简要介绍了Sqlite Client for Windows Phone的主要功能及相关的辅助开发工具。在接下来的第二篇文章中,我们将具体构建一个简单的Windows Phone 7客户端应用程序,当然要涉及到Sqlite Client for Windows Phone的基本编程技巧。

0
相关文章