Hi i'm new to linq and i'm trying to find the maximum size an inteeger can hold.
Dim Max As Integer = Convert.Int32((From a In mytable Order By a.Item("myValue") Select a.Item("Integer"))).MaxValue
it doesn't seem to be working? I asked a buddy and he said to use linq but i've never used it before.
You have a full sample in VB here : http://msdn.microsoft.com/en-us/vstudio/bb737922#maxsimp
Related
I have a postgresql database that contains program data. In Libreoffice Calc, I have Basic macros that interact with the postgresql database and uses Calc as the user client. One of the postgresql tables has an array and I can't index into that array directly from Basic.
Here is the table setup, as shown in pgAdmin:
sq_num integer,
year_start integer,
id serial NOT NULL,
"roleArray" text[]
Say I want to SELECT roleArray[50]. My every attempt to do this out of Basic results in the entire array being passed. I can certainly split the array myself and get the element I'm after, but I was using SQL arrays to help automate this stuff.
My Basic code uses a Libreoffice Base file for the connection to the postgresql database. Going to the Base file, I cannot create a query that will select an individual element and not return the entire array UNLESS I select the button "Run SQL command directly" and run this query:
SELECT "roleArray"['50'] FROM myTableThatHasArrays
Then I get element 50 from every record as intended.
I believe there is a bug report that describes this, where the Base command parser can't handle indexing an array. My question is what is the best method to overcome this?
The best scenario is to be able to index an element in the SQL array directly from Basic.
It sounds like you used XRow.getString, which (sensibly enough) retrieves the array as a single large string. Instead, use XRow.getArray and then XArray.getArray. Here is a working example:
sSQL = "SELECT id, ""roleArray""[2] FROM mytablethathasarrays;"
oResult = oStatement.executeQuery(sSQL)
s = ""
Do While oResult.next()
sql_array = oResult.getArray(2)
basic_array = sql_array.getArray(Null)
s = s & oResult.getInt(1) & " " & basic_array(1) & CHR$(10)
Loop
MsgBox s
I am trying to find number of rows in a ResultSet using idocscript. Is there an optimal way of doing other than looping through the ResultSet as below?
<$sampleRSLength=0$>
<$if rsExists("sampleResultSet")$>
<$loop sampleResultSet$>
<$sampleRSLength=sampleRSLength+1$>
<$endloop$>
<$endif$>
I was able to find the answer myself after reading through the IdocScript reference guide in detail.
Idocscript has a method rsNumRows() which can be used for getting number of rows in a result set.
<$if rsExists("sampleResultSet")$>
<$sampleRSLength=rsNumRows("sampleResultSet")$>
<$endif$>
<$sampleResultSet.#numRows$>
will also work.
Using LN 8.5.3 FP3, I am programmatically constructing a Query to pass to the FTSearch(Qry$, 0 ) function in LotusScript. Can anyone tell me what the maximum length the string can be before the Query cannot be executed?
The code is being run by a scheduled agent on a Notes 8.5.3 FP3 Server and htto url size is not applicable to the situation.
Anticipating your feedback and experiences..
Leon
as far as I see limit for 1 field/value is up to 128 characters, however as Michael noticed (in comments below) there could be many fields, very possibly with total size up to 16Kb.
you easy can do test yourself:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim Query As String
Dim i As integer
Set db = session.Currentdatabase
For i = 1 To 32000
Print i
Query = Query & "1"
Set col = db.Ftsearch({"} & Query & {"}, 0)
Next
In Lotusscript you can use a document collection and narrow it down with sequential smaller FTSearches. That way you might prevent the risk of getting a query that is too large.
I assume your query is more complex than just searching for a single string, read it may consist of multiple queryparametesr like [Form]="Memo" & [Subject]="Test" and so on. While the single search String (i.e. "Test") might be limited by 128 characters, the entire query is by far not limited to 128 Chars. We have created and used dynamic query that are much longer than that. I have seen queries exceeting 1024 Bytes and more and these were working. My guess is a limit of about 16kB for the entire query.
I'm tasked with adding an option to our search, which will return results where a given field doesn't begin with a letter of the alphabet. (The .StartsWith(letter) part wasn't so hard).
But I'm rather unsure about how to get the results that don't fall within the A-Z set, and equally hoping it generates some moderately efficient SQL underneath.
Any help appreciated - thanks.
In C# use the following construct, assuming db as a data context:
var query = from row in db.SomeTable
where !System.Data.Linq.SqlClient.SqlMethods.Like(row.SomeField, "[A-Z]%")
select row;
This is only supported in LINQ to SQL queries. All rules of the T-SQL LIKE operator apply.
You could also use less effective solution:
var query = from row in db.SomeTable
where row.SomeField[0] < 'A' || row.SomeField[0] > 'Z'
select row;
This gets translated into SUBSTRING, CAST, and UNICODE constructs.
Finally, you could use VB, where there appears to be a native support for the Like method.
Though SQL provides the ability to check a range of characters in a LIKE statement using bracket notation ([a-f]% for example), I haven't seen a linq to sql construct that supports this directly.
A couple thoughts:
First, if the result set is relatively small, you could do a .ToList() and filter in memory after the fact.
Alternatively, if you have the ability to change the data model, you could set up additional fields or tables to help index the data and improve the search.
--EDIT--
Made changes per Ruslan's comment below.
Well, I have no idea if this will work because I have never tried it and don't have a compiler nearby to try it, but the first thing I would try is
var query = from x in db.SomeTable
where x.SomeField != null &&
x.SomeField.Length >= 1 &&
x.SomeField.Substring(0, 1).All(c => !Char.IsLetter(c))
select x;
The possiblility exists that LINQ to SQL fails to convert this to SQL.
So I'm extremely new to Linq in .Net 3.5 and have a question. I use to use a custom class that would handle the following results from a store procedure:
Set 1: ID Name Age
Set 2: ID Address City
Set 3: ID Product Price
With my custom class, I would have received back from the database a single DataSet with 3 DataTables inside of it with columns based on what was returned from the DB.
My question is how to I achive this with LINQ? I'm going to need to hit the database 1 time and return multiple sets with different types of data in it.
Also, how would I use LINQ to return a dynamic amount of sets depending on the parameters (could get 1 set back, could get N amount back)?
I've looked at this article, but didn't find anything explaining multiple sets (just a single set that could be dynamic or a single scalar value and a single set).
Any articles/comments will help.
Thanks
I believe this is what you're looking for
Linq to SQL Stored Procedures with Multiple Results - IMultipleResults
I'm not very familiar with LINQ myself but here is MSDN's site on LINQ Samples that might be able to help you out.
EDIT: I apologize, I somehow missed the title where you mentioned you wanted help using LINQ with Stored Procedures, my below answer does not address that at all and unfortunately I haven't had the need to use sprocs with LINQ so I'm unsure if my below answer will help.
LINQ to SQL is able hydrate multiple sets of data into a object graph while hitting the database once. However, I don't think LINQ is going to achieve what you ultimately want -- which as far as I can tell is a completely dynamic set of data that is defined outside of the query itself. Perhaps I am misunderstanding the question, maybe it would help if you provide some sample code that your existing application is using?
Here is a quick example of how I could hydrate a anonymous type with a single database call, maybe it will help:
var query = from p in db.Products
select new
{
Product = p,
NumberOfOrders = p.Orders.Count(),
LastOrderDate = p.Orders.OrderByDescending().Take(1).Select(o => o.OrderDate),
Orders = p.Orders
};