Skip to content

Commit 0526a76

Browse files
committed
Add IStatement/IAsyncStatement.Query methods.
1 parent bf2f113 commit 0526a76

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

SQLitePCL.pretty.Async/AsyncStatement.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ public static Task ExecuteAsync(
141141
{
142142
return This.ExecuteAsync(CancellationToken.None, values);
143143
}
144+
145+
/// <summary>
146+
/// Queries the database asynchronously using the provided IStatement and provided bind variables.
147+
/// </summary>
148+
/// <param name="This">The async statement.</param>
149+
/// <param name="values">The position indexed values to bind.</param>
150+
/// <returns>A cold IObservable of the rows in the result set.</returns>
151+
public static IObservable<IReadOnlyList<IResultSetValue>> Query(
152+
this IAsyncStatement This,
153+
params object[] values)
154+
{
155+
return This.Use<IReadOnlyList<IResultSetValue>>(stmt => stmt.Query(values));
156+
}
157+
158+
/// <summary>
159+
/// Queries the database asynchronously using the provided IStatement
160+
/// </summary>
161+
/// <param name="This">The async statement.</param>
162+
/// <returns>A cold IObservable of the rows in the result set.</returns>
163+
public static IObservable<IReadOnlyList<IResultSetValue>> Query(this IAsyncStatement This)
164+
{
165+
return This.Use<IReadOnlyList<IResultSetValue>>(stmt => stmt.Query());
166+
}
144167
}
145168

146169
internal class AsyncStatementImpl : IAsyncStatement

SQLitePCL.pretty/DatabaseConnection.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,10 @@ public static IEnumerable<IReadOnlyList<IResultSetValue>> Query(
294294
Contract.Requires(This != null);
295295
Contract.Requires(sql != null);
296296

297-
object[] empty = { };
298-
return This.Query(sql, empty);
297+
return new DelegatingEnumerable<IReadOnlyList<IResultSetValue>>(() =>
298+
{
299+
return This.PrepareStatement(sql);
300+
});
299301
}
300302

301303
/// <summary>

SQLitePCL.pretty/Statement.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
*/
1717

1818
using System;
19+
using System.Collections.Generic;
1920
using System.Diagnostics.Contracts;
2021
using System.IO;
2122

@@ -91,5 +92,44 @@ public static void Execute(this IStatement This, params object[] values)
9192
This.Bind(values);
9293
This.MoveNext();
9394
}
95+
96+
/// <summary>
97+
/// Queries the database using the provided IStatement and provided bind variables.
98+
/// </summary>
99+
/// <param name="This">The statements.</param>
100+
/// <param name="values">The position indexed values to bind.</param>
101+
/// <returns>An <see cref="IEnumerable&lt;T&gt;"/> of rows in the result set.</returns>
102+
public static IEnumerable<IReadOnlyList<IResultSetValue>> Query(
103+
this IStatement This,
104+
params object[] values)
105+
{
106+
Contract.Requires(This != null);
107+
Contract.Requires(values != null);
108+
109+
return new DelegatingEnumerable<IReadOnlyList<IResultSetValue>>(() =>
110+
{
111+
This.Reset();
112+
This.ClearBindings();
113+
This.Bind(values);
114+
return This;
115+
});
116+
}
117+
118+
/// <summary>
119+
/// Queries the database using the provided IStatement.
120+
/// </summary>
121+
/// <param name="This">The statements.</param>
122+
/// <returns>An <see cref="IEnumerable&lt;T&gt;"/> of rows in the result set.</returns>
123+
public static IEnumerable<IReadOnlyList<IResultSetValue>> Query(this IStatement This)
124+
{
125+
Contract.Requires(This != null);
126+
127+
return new DelegatingEnumerable<IReadOnlyList<IResultSetValue>>(() =>
128+
{
129+
This.Reset();
130+
This.ClearBindings();
131+
return This;
132+
});
133+
}
94134
}
95135
}

0 commit comments

Comments
 (0)