Showing the result of a query - sql

I'm trying to build a query to get the numbers of rows that have the same data on a column (my column is ESTADO).
var db = Database.Open("MyDB");
var selectedData = db.Query("SELECT COUNT (*) FROM graficos WHERE ESTADO='FECHADO'");
var data = db.QueryValue(selectedData);
But when i try to run it gives the following error:
Compiler Error Message: CS1502: The best overloaded method match for 'WebMatrix.Data.Database.QueryValue(string, params object[])' has some invalid arguments
Line 51: var data = db.QueryValue(selectedData);

Pass the query directly to the QueryValue() method.
var data = db.QueryValue("SELECT COUNT (*) FROM graficos WHERE ESTADO='FECHADO'");
Read this documentation for more information on how to use the Database.QueryValue() method.

Related

Salesforce Apex: Error ORA-01460

I've developed an apex API on salesforce which performs a SOQL on a list of CSV data. It has been working smoothly until yesterday, after making a few changes to code that follow the SOQL query, I started getting a strange 500 error:
[{"errorCode":"APEX_ERROR","message":"System.UnexpectedException:
common.exception.SfdcSqlException: ORA-01460: unimplemented or
unreasonable conversion requested\n\n\nselect /SampledPrequery/
sum(term0) \"cnt0\",\nsum(term1) \"cnt1\",\ncount(*)
\"totalcount\",\nsum(term0 * term1) \"combined\"\nfrom (select /*+
ordered use_nl(t_c1) /\n(case when (t_c1.deleted = '0') then 1 else 0
end) term0,\n(case when (upper(t_c1.val18) = ?) then 1 else 0 end)
term1\nfrom (select /+ index(sampleTab AKENTITY_SAMPLE)
*/\nentity_id\nfrom core.entity_sample sampleTab\nwhere organization_id = '00Dq0000000AMfz'\nand key_prefix = ?\nand rownum <=
?) sampleTab,\ncore.custom_entity_data t_c1\nwhere
t_c1.organization_id = '00Dq0000000AMfz'\nand t_c1.key_prefix = ?\nand
sampleTab.entity_id =
t_c1.custom_entity_data_id)\n\nClass.labFlows.queryContacts: line 13,
column 1\nClass.labFlows.fhaQuery: line 6, column
1\nClass.zAPI.doPost: line 10, column 1"}]
the zAPI.doPost() is simply our router class which takes in the post payload as well as the requested operation. It then calls whatever function the operation requests. In this case, the call is to labFlows.queryContacts():
Public static Map<string,List<string>> queryContacts(string[] stringArray){
//First get the id to get to the associative entity, Contact_Deals__c id
List<Contact_Deals__c> dealQuery = [SELECT id, Deal__r.id, Deal__r.FHA_Number__c, Deal__r.Name, Deal__r.Owner.Name
FROM Contact_Deals__c
Where Deal__r.FHA_Number__c in :stringArray];
//Using the id in the associative entity, grab the contact information
List<Contact_Deals__c> contactQuery = [Select Contact__r.Name, Contact__r.Id, Contact__r.Owner.Name, Contact__r.Owner.Id, Contact__r.Rule_Class__c, Contact__r.Primary_Borrower_Y_N__c
FROM contact_deals__c
WHERE Id in :dealQuery];
//Grab all deal id's
Map<string,List<string>> result = new Map<string,List<string>>();
for(Contact_Deals__c i:dealQuery){
List<string> temp = new list<string>();
temp.add(i.Deal__r.Id);
temp.add(i.Deal__r.Owner.Name);
temp.add(i.Deal__r.FHA_Number__c);
temp.add(i.Deal__r.Name);
for(Contact_Deals__c j:contactQuery){
if(j.id == i.id){
//This doesn't really help if there are multiple primary borrowers on a deal - but that should be a SF worflow rule IMO
if(j.Contact__r.Primary_Borrower_Y_N__c == 'Yes'){
temp.add(j.Contact__r.Owner.Id);
temp.add(j.Contact__r.Id);
temp.add(j.Contact__r.Name);
temp.add(j.Contact__r.Owner.Name);
temp.add(j.Contact__r.Rule_Class__c);
break;
}
}
}
result.put(i.Deal__r.id, temp);
}
return result;
}
The only thing I've changed is moving the temp list to add elements before the inner-loop (previously temp would only capture things from the inner-loop). The error above is referencing line 13, which is specifically the first SOQL call:
List<Contact_Deals__c> dealQuery = [SELECT id, Deal__r.id, Deal__r.FHA_Number__c, Deal__r.Name, Deal__r.Owner.Name
FROM Contact_Deals__c
Where Deal__r.FHA_Number__c in :stringArray];
I've tested this function in the apex anonymous window and it worked perfectly:
string a = '00035398,00035401';
string result = zAPI.doPost(a, 'fhaQuery');
system.debug(result);
Results:
13:36:54:947 USER_DEBUG
[5]|DEBUG|{"a09d000000HRvBAD":["a09d000000HRvBAD","Contacta","11111111","Plaza
Center
Apts"],"a09d000000HsVAD":["a09d000000HsVAD","Contactb","22222222","The
Garden"]}
So this is working. The next part is maybe looking at my python script that is calling the API,
def origQuery(file_name, operation):
csv_text = ""
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
data = json.dumps({
'data' : csv_text,
'operation' : operation
})
results = requests.post(url, headers=headers, data=data)
print results.text
origQuery('myfile.csv', 'fhaQuery')
I've tried looking up this ORA-01460 apex error, but I can't find anything that will help me fix this issue.
Can any one shed ore light on what this error is telling me?
Thank you all so much!
It turns out the error was in the PY script. For some reason the following code isn't functioning as it is supposed to:
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
This was returning one very long string that had zero delimiters. The final line in the code was cutting off the delimiter. What I needed instead was:
with open(file_name) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
csv_text += row[0]+','
csv_text = csv_text[:-1]
Which would cut off the final ','
The error was occurring because the single long string was above 4,000 characters.

How do I correct the "Object Expected" Error when it inloves var queryStringVals = $().SPServices.SPGetQueryString();?

Hi have been getting an error stating.. Object Expected for these 2 lines of code:
function AsyncSave(send) {
//alert ('In CustomSave');
var drp = document.getElementById("Sample_sample_DropDownChoice");
var drpValue = drp.options[drp.selectedIndex].value;
var varAnalysis = getTagFromIdentifierAndTitle("textarea","TextField","Principal Comments");
var varAnalysisTextBoxID = RTE_GetEditorDocument(varAnalysis.id);
var varAnalysisText = varAnalysisTextBoxID.body.innerText;
alert ('Save N Send');
alert (drpValue);
alert (varAnalysisText);
Error Happens when it gets to the line below
var queryStringVals = $().SPServices.SPGetQueryString();
var itemID = queryStringVals["itemID"];
What could be the problem.. should I be running different up to date SPServices.. this is 2010 btw.
The goal is to take the values entered, save them, and update them (send) to another form/List.
SharePoint 2010 has a built-in JavaScript method for retrieving values from the query string. Try using the following:
var itemID = GetUrlKeyValue("itemID");
That's assuming the URL of the page on which the script is running actually has a query string parameter of "itemID"

"update" query - error invalid input synatx for integer: "{39}" - postgresql

I'm using node js 0.10.12 to perform querys to postgreSQL 9.1.
I get the error error invalid input synatx for integer: "{39}" (39 is an example number) when I try to perform an update query
I cannot see what is going wrong. Any advise?
Here is my code (snippets) in the front-end
//this is global
var gid=0;
//set websockets to search - works fine
var sd = new WebSocket("ws://localhost:0000");
sd.onmessage = function (evt)
{
//get data, parse it, because there is more than one vars, pass id to gid
var received_msg = evt.data;
var packet = JSON.parse(received_msg);
var tid = packet['tid'];
gid=tid;
}
//when user clicks button, set websockets to send id and other data, to perform update query
var sa = new WebSocket("ws://localhost:0000");
sa.onopen = function(){
sa.send(JSON.stringify({
command:'typesave',
indi:gid,
name:document.getElementById("typename").value,
}));
sa.onmessage = function (evt) {
alert("Saved");
sa.close;
gid=0;//make gid 0 again, for re-use
}
And the back -end (query)
var query=client.query("UPDATE type SET t_name=$1,t_color=$2 WHERE t_id = $3 ",[name, color, indi])
query.on("row", function (row, result) {
result.addRow(row);
});
query.on("end", function (result) {
connection.send("o");
client.end();
});
Why this not work and the number does not get recognized?
Thanks in advance
As one would expect from the initial problem, your database driver is sending in an integer array of one member into a field for an integer. PostgreSQL rightly rejects the data and return an error. '{39}' in PostgreSQL terms is exactly equivalent to ARRAY[39] using an array constructor and [39] in JSON.
Now, obviously you can just change your query call to pull the first item out of the JSON array. and send that instead of the whole array, but I would be worried about what happens if things change and you get multiple values. You may want to look at separating that logic out for this data structure.

QueryOver IN Clause?

I want to simulate this query:
SELECT * FROM FOO WHERE ID IN (1,2,3)
How can I do this in FNH?
var ids = new List<int>{1,2,3};
var results = session.QueryOver<Foo>().Where( x=> ids.Contains(x.id) );
But that does not work, just gives me an "unrecognized method call" exception.
Any ideas? This must be a common request.
Aha- got it! The AddRestrictions has an IsIn method:
var results = session.QueryOver<Foo>().AndRestrictionOn(x=>x.id).IsIn(ids)
With this last piece we might be ready to ditch our years-old hand-rolled ORM!

Windows8: device identifier

I am currently trying to retrieve a unique device identifier. Here is my code:
var token = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);
var reader = Windows.Storage.Streams.DataReader.fromBuffer(token.id);
reader.unicodeEncoding = true;
var identifier = reader.readString(reader.unconsumedBufferLength);
console.log(identifier);
But it raises following error:
The operation attempted to access data outside the valid range.
How can I retrieve the size of my token.id string? I also tried to use token.id.length, but result is the same.
I can't try to replicate what you're doing at the moment, but you might try reading it as bytes into array like this:
var array = new Array(token.id.length);
reader.readBytes(array);
And then convert the array to a string for the identifier.
See these posts for examples:
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/1e2175e3-fe07-4094-9454-b3ecf1bf0381
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cdf72b9f-b3c0-488e-b607-b4445a5039b3