Skip to content

Commit

Permalink
Allow null values
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Wallstrom committed Apr 6, 2010
1 parent 8c17dd8 commit 45d1f2d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
Binary file modified lib/Newtonsoft.Json.dll
Binary file not shown.
13 changes: 11 additions & 2 deletions src/CouchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CouchQuery Keys(IList<object> keys)
/// </summary>
public CouchQuery Key(object value)
{
Options["key"] = JToken.FromObject(value).ToString();
Options["key"] = value == null ? "null" : JToken.FromObject(value).ToString();
return this;
}

Expand Down Expand Up @@ -257,7 +257,16 @@ public CouchRequest Request()
}
}

JObject json = req.Parse();
JObject json;
try
{
json = req.Parse();
}
catch(WebException e)
{
throw CouchException.Create("Query failed", e);
}

if (json != null) // ETag did not match, view has changed
{
Result.Result(json);
Expand Down
40 changes: 28 additions & 12 deletions src/CouchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ public class CouchRequest
private Stream postStream;
private readonly CouchServer server;
private string etag, etagToCheck;
public Dictionary<string, string> headers = new Dictionary<string, string>();
private Dictionary<string, string> headers = new Dictionary<string, string>();

// Query options
public string method = "GET"; // PUT, DELETE, POST, HEAD
public string mimeType;
public string path;
public string query;
private string method = "GET"; // PUT, DELETE, POST, HEAD
private string mimeType;
private string path;
private string query;

public JToken result;
private JToken result;

#region Contructors

public CouchRequest(CouchServer server)
{
Expand All @@ -42,22 +44,39 @@ public CouchRequest(CouchDatabase db)
this.db = db;
}

#endregion

/// <summary>
/// Sets the e-tag value
/// </summary>
/// <param name="value">The e-tag value</param>
/// <returns>A CouchRequest with the new e-tag value</returns>
public CouchRequest Etag(string value)
{
etagToCheck = value;
headers["If-Modified"] = value;
return this;
}

/// <summary>
/// Sets the absolute path in the query
/// </summary>
/// <param name="name">The absolute path</param>
/// <returns>A <see cref="CouchRequest"/> with the new path set.</returns>
public CouchRequest Path(string name)
{
path = name;
return this;
}

public CouchRequest Query(string name)
/// <summary>
/// Sets the raw query information in the request. Don't forget to start with a question mark (?).
/// </summary>
/// <param name="value">The raw query</param>
/// <returns>A <see cref="CouchRequest"/> with the new query set.</returns>
public CouchRequest Query(string value)
{
query = name;
query = value;
return this;
}

Expand Down Expand Up @@ -251,8 +270,6 @@ public JObject Parse()

public T Parse<T>() where T : JToken
{
//var timer = new Stopwatch();
//timer.Start();
using (WebResponse response = GetResponse())
{
using (Stream stream = response.GetResponseStream())
Expand All @@ -274,8 +291,7 @@ public T Parse<T>() where T : JToken
}
}
}
//timer.Stop();
//Trace.WriteLine("Time for Couch HTTP & JSON PARSE: " + timer.ElapsedMilliseconds);

return (T)result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Divan.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{37AC0B66-5340-4B81-BC62-3EE80233A011}</ProjectGuid>
<OutputType>Library</OutputType>
Expand Down Expand Up @@ -31,7 +31,7 @@
<WarningLevel>3</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand Down

0 comments on commit 45d1f2d

Please sign in to comment.