How to retrieve Oracle Clob more than 4000 characters ODP.NET - c#-4.0

I am trying to retrieve CLOB data via ODP.NET.
My problem is that reader.GetValue(i).ToString() can return only up to 4000 characters and the rest of the data is truncated.
If I use reader.GetOracleClob(1).Value I got "Specified cast is not valid" error.
Any idea what I have missed? I am using ODP.NET 4.0
Below is my code.
using (OracleConnection oConn = new OracleConnection())
{
oConn.ConnectionString = pConnstr;
oConn.Open();
using (OracleCommand oCmd = new OracleCommand("select varchar_column, clob_column from test", oConn))
{
oCmd.InitialLOBFetchSize = -1;
string key, value, value1;
var rd = oCmd.ExecuteReader();
while (rd.Read())
{
if (rd.IsDBNull(1)) { value = ""; }
else
{
key = rd.GetValue(0).ToString();
value = rd.GetValue(1).ToString(); // unable to get more than 4000.
value1 = rd.GetOracleClob(1).Value; // Specified cast is not valid.
}
}
}
}
I found in Oracle Doc that When the InitialLOBFetchSize property is set to a nonzero value, the GetOracleBlob, GetOracleClob, GetOracleBlobForUpdate, and GetOracleClobForUpdate typed accessor methods are disabled. That may help explain why I got "Specified cast is not valid" error.
However, I still cannot get data beyond 4000 limit.
I have tried different combinations documented here
http://docs.oracle.com/cd/E11882_01/win.112/e18754/featData.htm#autoId6
But no luck.

Actually the code works correctly and gets the data it supposed to get. I just didn't realize that my data is incomplete and appeared to be a retrieval problem at the first look. Sorry.
The following is the good code.
using (OracleConnection oConn = new OracleConnection())
{
oConn.ConnectionString = pConnstr;
oConn.Open();
using (OracleCommand oCmd = new OracleCommand("select varchar_column, clob_column from test", oConn))
{
oCmd.InitialLOBFetchSize = -1;
string key, value;
var rd = oCmd.ExecuteReader();
while (rd.Read())
{
if (rd.IsDBNull(1)) { value = ""; }
else
{
key = rd.GetValue(0).ToString();
value = rd.GetValue(1).ToString();
}
}
}
}

The above solution did not work for me. It turns out my data was not CLOB or BLOB but LONG Data! So the fix is just to set:
oCmd.InitialLONGFetchSize= -1;
Instead of
oCmd.InitialLOBFetchSize = -1;
Please leave a comment if this method worked for you also.

Related

What would be the reason that I can't make the ElementIDs of these objects in Revit match ones in a Revit file?

I am creating a plugin that makes use of the code available from BCFier to select elements from an external server version of the file and highlight them in a Revit view, except the elements are clearly not found in Revit as all elements appear and none are highlighted. The specific pieces of code I am using are:
private void SelectElements(Viewpoint v)
{
var elementsToSelect = new List<ElementId>();
var elementsToHide = new List<ElementId>();
var elementsToShow = new List<ElementId>();
var visibleElems = new FilteredElementCollector(OpenPlugin.doc, OpenPlugin.doc.ActiveView.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElementIds()
.Where(e => OpenPlugin.doc.GetElement(e).CanBeHidden(OpenPlugin.doc.ActiveView)); //might affect performance, but it's necessary
bool canSetVisibility = (v.Components.Visibility != null &&
v.Components.Visibility.DefaultVisibility &&
v.Components.Visibility.Exceptions.Any());
bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any());
//loop elements
foreach (var e in visibleElems)
{
//string guid = ExportUtils.GetExportId(OpenPlugin.doc, e).ToString();
var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(OpenPlugin.doc, e));
Trace.WriteLine(guid.ToString());
if (canSetVisibility)
{
if (v.Components.Visibility.DefaultVisibility)
{
if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
elementsToHide.Add(e);
}
else
{
if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid))
elementsToShow.Add(e);
}
}
if (canSetSelection)
{
if (v.Components.Selection.Any(x => x.IfcGuid == guid))
elementsToSelect.Add(e);
}
}
try
{
OpenPlugin.HandlerSelect.elementsToSelect = elementsToSelect;
OpenPlugin.HandlerSelect.elementsToHide = elementsToHide;
OpenPlugin.HandlerSelect.elementsToShow = elementsToShow;
OpenPlugin.selectEvent.Raise();
} catch (System.Exception ex)
{
TaskDialog.Show("Exception", ex.Message);
}
}
Which is the section that should filter the lists, which it does do as it produces IDs that look like this:
3GB5RcUGnAzQe9amE4i4IN
3GB5RcUGnAzQe9amE4i4Ib
3GB5RcUGnAzQe9amE4i4J6
3GB5RcUGnAzQe9amE4i4JH
3GB5RcUGnAzQe9amE4i4Ji
3GB5RcUGnAzQe9amE4i4J$
3GB5RcUGnAzQe9amE4i4GD
3GB5RcUGnAzQe9amE4i4Gy
3GB5RcUGnAzQe9amE4i4HM
3GB5RcUGnAzQe9amE4i4HX
3GB5RcUGnAzQe9amE4i4Hf
068MKId$X7hf9uMEB2S_no
The trouble with this is, comparing it to the list of IDs in the IFC file that we imported it from reveals that these IDs do not appear in the IFC file, and looking at it in Revit I found that none of the Guids in Revit weren't in the list that appeared either. Almost all the objects also matched the same main part of the IDs as well, and I'm not experienced enough to know how likely that is.
So my question is, is it something in this code that is an issue?
The IFC GUID is based on the Revit UniqueId but not identical. Please read about the Element Identifiers in RVT, IFC, NW and Forge to learn how they are connected.

Suitescript check if field is searchable

I am trying to search Account data using SuiteScript 1.0 in netsuite, but I am getting "SS_INVALID_SRCH_COL Details: An nlobjSearchColumn contains an invalid column, or is not in proper syntax:" error. I am using Admin role for my login. following the code sample that causing error
function getMasterData(datain)
{
try
{
var recordtype = 'account';
var c;
var strcolumns = nlapiCreateRecord(recordtype).getAllFields();
var searchcolumns = [];
for (c = 0; strcolumns.length && c < strcolumns.length; c += 1)
{
searchcolumns.push(new nlobjSearchColumn(strcolumns[c]));
}
var data = nlapiSearchRecord(recordtype, null, null, searchcolumns);
return data;
}
catch (ex)
{
nlapiLogExecution('debug', 'getMasterData', ex);
}
}
I know the reason: getAllFields() returns all the fields (searchable/nonsearchable) but nlapiSearchRecord works only for searchable fields. My query is how I can filter searchable fields in the all fields returned by getAllFields() function.
Can please anybody help me regarding this. Thanks in advance.
There's no way to know if a field can be used in a search but you can get the supported fields from the Records Browser and create an array with them.
Note that you can get a record with all fields and values using nlapiLoadRecord.

Using getAttribute to get the class name of a webelement in Native context

Went through the java docs of getAttribute. Couldn't understand the point mentioned as :
Finally, the following commonly mis-capitalized attribute/property
names are evaluated as expected: "class" "readonly"
Could someone confirm if webElement.getAttribute("class") shall return the class name of the element or not?
Edit : On trying this myself
System.out.println("element " + webElement.getAttribute("class"));
I am getting
org.openqa.selenium.NoSuchElementException
Note : The element does exist on the screen as I can perform actions successfully on the element :
webElement.click(); //runs successfully
Code:
WebElement webElement = <findElement using some locator strategy>;
System.out.println("element " + webElement.getAttribute("class"));
So the answer to the problem was answered on GitHub in the issues list of appium/java-client by #SergeyTikhomirov. Simple solution to this is accessing the className property as following :
webElement.getAttribute("className")); //instead of 'class' as mentioned in the doc
Method core implementation here : AndroidElement
According to this answer, yes you are doing it right. Your org.openqa.selenium.NoSuchElementException is thrown because selenium can't find the element itself.
The sidenote you have posted, about webElement.click() actually working, is unfortunately not included in the code you have posted. Since it is not a part of the actual question, I leave this answer without adressing it.
public String getStringAttribute(final String attr)
throws UiObjectNotFoundException, NoAttributeFoundException {
String res;
if (attr.equals("name")) {
res = getContentDesc();
if (res.equals("")) {
res = getText();
}
} else if (attr.equals("contentDescription")) {
res = getContentDesc();
} else if (attr.equals("text")) {
res = getText();
} else if (attr.equals("className")) {
res = getClassName();
} else if (attr.equals("resourceId")) {
res = getResourceId();
} else {
throw new NoAttributeFoundException(attr);
}
return res;
}

Distinct values in Azure Search Suggestions?

I am offloading my search feature on a relational database to Azure Search. My Products tables contains columns like serialNumber, PartNumber etc.. (there can be multiple serialNumbers with the same partNumber).
I want to create a suggestor that can autocomplete partNumbers. But in my scenario I am getting a lot of duplicates in the suggestions because the partNumber match was found in multiple entries.
How can I solve this problem ?
The Suggest API suggests documents, not queries. If you repeat the partNumber information for each serialNumber in your index and then suggest based on partNumber, you will get a result for each matching document. You can see this more clearly by including the key field in the $select parameter. Azure Search will eliminate duplicates within the same document, but not across documents. You will have to do that on the client side, or build a secondary index of partNumbers just for suggestions.
See this forum thread for a more in-depth discussion.
Also, feel free to vote on this UserVoice item to help us prioritize improvements to Suggestions.
I'm facing this problem myself. My solution does not involve a new index (this will only get messy and cost us money).
My take on this is a while-loop adding 'UserIdentity' (in your case, 'partNumber') to a filter, and re-search until my take/top-limit is met or no more suggestions exists:
public async Task<List<MachineSuggestionDTO>> SuggestMachineUser(string searchText, int take, string[] searchFields)
{
var indexClientMachine = _searchServiceClient.Indexes.GetClient(INDEX_MACHINE);
var suggestions = new List<MachineSuggestionDTO>();
var sp = new SuggestParameters
{
UseFuzzyMatching = true,
Top = 100 // Get maximum result for a chance to reduce search calls.
};
// Add searchfields if set
if (searchFields != null && searchFields.Count() != 0)
{
sp.SearchFields = searchFields;
}
// Loop until you get the desired ammount of suggestions, or if under desired ammount, the maximum.
while (suggestions.Count < take)
{
if (!await DistinctSuggestMachineUser(searchText, take, searchFields, suggestions, indexClientMachine, sp))
{
// If no more suggestions is found, we break the while-loop
break;
}
}
// Since the list might me bigger then the take, we return a narrowed list
return suggestions.Take(take).ToList();
}
private async Task<bool> DistinctSuggestMachineUser(string searchText, int take, string[] searchFields, List<MachineSuggestionDTO> suggestions, ISearchIndexClient indexClientMachine, SuggestParameters sp)
{
var response = await indexClientMachine.Documents.SuggestAsync<MachineSearchDocument>(searchText, SUGGESTION_MACHINE, sp);
if(response.Results.Count > 0){
// Fix filter if search is triggered once more
if (!string.IsNullOrEmpty(sp.Filter))
{
sp.Filter += " and ";
}
foreach (var result in response.Results.DistinctBy(r => new { r.Document.UserIdentity, r.Document.UserName, r.Document.UserCode}).Take(take))
{
var d = result.Document;
suggestions.Add(new MachineSuggestionDTO { Id = d.UserIdentity, Namn = d.UserNamn, Hkod = d.UserHkod, Intnr = d.UserIntnr });
// Add found UserIdentity to filter
sp.Filter += $"UserIdentity ne '{d.UserIdentity}' and ";
}
// Remove end of filter if it is run once more
if (sp.Filter.EndsWith(" and "))
{
sp.Filter = sp.Filter.Substring(0, sp.Filter.LastIndexOf(" and ", StringComparison.Ordinal));
}
}
// Returns false if no more suggestions is found
return response.Results.Count > 0;
}
public async Task<List<string>> SuggestionsAsync(bool highlights, bool fuzzy, string term)
{
SuggestParameters sp = new SuggestParameters()
{
UseFuzzyMatching = fuzzy,
Top = 100
};
if (highlights)
{
sp.HighlightPreTag = "<em>";
sp.HighlightPostTag = "</em>";
}
var suggestResult = await searchConfig.IndexClient.Documents.SuggestAsync(term, "mysuggestion", sp);
// Convert the suggest query results to a list that can be displayed in the client.
return suggestResult.Results.Select(x => x.Text).Distinct().Take(10).ToList();
}
After getting top 100 and using distinct it works for me.
You can use the Autocomplete API for that where does the grouping by default. However, if you need more fields together with the result, like, the partNo plus description it doesn't support it. The partNo will be distinct though.

NpqsqlParameter - Multiple Values

Code:
string sqlCommand = #"UPDATE table SET active = 0 WHERE id IN (#CommaSeparatedId)";
string sqlParamName = "CommaSeparatedId";
string sqlParamValue = "111, 222";
try
{
using (NpgsqlConnection connection = new NpgsqlConnection())
{
// Get connection string from Web.config
connection.ConnectionString = _connectionString;
connection.Open();
Int32 rowsAffected;
using (NpgsqlCommand command = new NpgsqlCommand(sqlCommand, connection))
{
NpgsqlParameter sqlParam = new NpgsqlParameter(sqlParamName, NpgsqlTypes.NpgsqlDbType.Varchar);
// Code below no exception occur, and active not updated to 0
// sqlParam.Value = sqlParamValue;
// This code works for only one value
sqlParam.Value = "111";
command.Parameters.Add(sqlParam);
rowsAffected = command.ExecuteNonQuery();
}
}
}
catch (NpgsqlException pgEx)
{
throw pgEx;
}
The problem is:
If I'm using the 111, 222 as the sqlParam.Value'rowsAffected = 0, but if I'm using only111or222rowsAffected = 1`. That means it success to updated when only 1 value but will failed if trying to update more than 1 value.
Expected Query:
UPDATE table
SET active = 0
WHERE id IN ('111', '222');
What I'm missing in code above?
The problem you are facing is due to the fact that the parameter value "111,222" will be seen by the database engine not like two distinct values, but as one.
The database search for a record with ID = "111,222" and find nothing matching the request.
You should try to use a stored procedure and execute a Dynamic SQL according to the syntax required by PostgreSQL

Resources