How do I run a Dynamic SQL Query in Webmatrix? - sql

I'm working on something in WebMatrix that runs an SQL Query. I can do that, however, it Selects * From UserProfile WHERE Email = #WebSecurity.CurrentUserName. I have no idea how to get it to read only a column where Email = #WebSecurity.CurrentUserName. I listed my code below.
#{
var db=Database.Open("AeroSC");
var sqlQ = "SELECT * FROM UserProfile";
var data = db.Query(sqlQ);
}
How do I go about doing this?
Thanks!

#{
var db = Database.Open("AeroSC");
var sqlQ = "SELECT Id FROM UserProfile WHERE Email = #0";
var id = db.QueryValue(sqlQ, WebSecurity.CurrentUserName);
}

Related

Google Apps Script query to MariaDB

We recently moved our data to a new server - however the new one is using MariaDB.
We do a lot of queries and calculations in Google Apps Script for spreadsheet. Since the server switch our scripts return the following error:
Unknown system variable 'OPTION' (line 21, file "")
Line 21 refers to the query inside the following script:
function mysql_invoice() {
// Replace the variables in this block with real values.
var address = 'xxx';
var user = 'xxx';
var userPwd = 'xxx';
var db = 'xxx';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
// Read up to 100000 rows of data from the table and log them.
var conn = Jdbc.getConnection(dbUrl, user, userPwd);
var stmt = conn.createStatement();
// Call SO DATA
stmt.setMaxRows(10000);
var start = new Date();
var rs = stmt.executeQuery("select * from sales_flat_invoice");
Any ideas?
I believe the way you used setMaxRows is the problem.
If you change the way you set the limit it will work.
// Call SO DATA
// stmt.setMaxRows(10000);
var start = new Date();
var rs = stmt.executeQuery("select * from sales_flat_invoice limit 10000");
This should fix your problem. This definetly comes from the missmatch of version of your MariaDB and the version of jdbc connector.
Cheers

how to update a column in force.com explorer

SELECT Name, ProfileId, Id, Username FROM User this is the select query to retrive data in Force.com explorer
Now I wan't to update a column how can I do this? update key word it self not working here please give the solution for this.
thanks in advance
In Salesforce you not write to update query same as in SQL.
Please use update method to update column of an object.
More information and sample please read following documents.
https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update.htm
I found Solution it's working fine now, If any one haveing doubts ask me for Create,Update,Get functionalities
private void UpdateProfileId(string Id)
{
SforceService sfs = new SforceService();
var login = sfs.login(ConfigurationManager.AppSettings["username"],ConfigurationManager.AppSettings["password"]);
sfs.Url = login.serverUrl;
sfs.SessionHeaderValue = new SessionHeader();
sfs.SessionHeaderValue.sessionId = login.sessionId;
var userinfo = login.userInfo;
QueryResult qr = null;
sfs.QueryOptionsValue = new salesforce.QueryOptions();
User[] UpdateUser = new User[1];
User objuser = new User();
objuser.Id = Id;
objuser.ProfileId = "00e90000001CcTnAAK";
UpdateUser[0] = objuser;
try
{
SaveResult[] saveResults = sfs.update(UpdateUser);
foreach (SaveResult saveResult in saveResults)
{
if (saveResult.success)
{
Console.WriteLine("Successfully updated Account ID: " +saveResult.id);
}
}
}
}

SELECT issue moving from PG_query to PDO

I have a select statement see below. Using PDO how would I recreate this same Select statement, as I want to grab two values from it and combine them into the $geomstring. I can figure out the combine, but not the first 3 lines.
$sql1 = "SELECT easting_value, northing_value FROM gridreference_tbl WHERE gridref_id='$_POST[gridref_id]'";
$result1 = pg_query($sql1);
$row1 = pg_fetch_array($result1);
$geomstring = $row1['easting_value']. $_POST['grid_eastings']." ".$row1['northing_value'].$_POST['grid_northings'];
*php website for prepared statements says *
$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
I have something similar working for populating a dropdown that partly uses this
$stmt = $conn->prepare("SELECT easting_value, northing_value FROM gridreference_tbl WHERE gridref_id=$gridref_id");
$stmt->setFetchMode(PDO::FETCH_OBJ);
Found it on php.net, I was googling the wrong stuff:
$stmt4 = $conn->prepare("SELECT easting_value, northing_value from gridreference_tbl WHERE gridref_id = 4");
$stmt4->execute();
print("PDO::FETCH_ASSOC: ");
print("Return next row as an array indexed by column name\n");
$result = $stmt4->fetch(PDO::FETCH_ASSOC);
print_r($result);
print("\n");

SQL Syntax for date range in a multiple search query

I have this code written so far and it works for what I am doing but if I search for June 13 it will only look up until June 12, can someone help me figure whats wrong in my code? or where I can add a day interval? I tried and its just not working for me.
var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var fromDate= "";
var toDate= "";
formSSO = Request.QueryString["formSSO"];
fromDate = Request.QueryString["fromDate"];
toDate = Request.QueryString["toDate"];
selectCommand = "(SELECT * from RMS WHERE SSO LIKE #0)";
if(!Request.QueryString["fromDate"].IsEmpty() ) {
selectCommand = "SELECT * FROM RMS WHERE SSO LIKE #0 AND Created BETWEEN #1 AND #2";
}
if(Request.QueryString["formSSO"].IsEmpty() ) {
<div class="simple"><strong>*SSO ID is Required.</strong></div>
}
var data = db.Query(selectCommand, formSSO, fromDate, toDate);
var columns = new[]{"ID", "SSO", "Category", "System", "Subject", "Created"};
var grid = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns);
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) {
grid.SortDirection = SortDirection.Descending;
}
}
One thing you can try is using <= and >= instead of BETWEEN like this:
selectCommand = "SELECT * FROM RMS WHERE SSO LIKE #0 AND Created >= #1 AND Created <= #2";
I hope that does the trick!
If not you can also brute force the to date to be one day further into the future and then use the BETWEEN operator just you are now like this:
DateTime to_date = Convert.ToDateTime(to_date_string);
to_date = to_date.AddDays(1);
to_date_string = to_date.ToString();

Rally: Query Filtered to Specific Tags

I am writing a custom app for Rally and I would like to filter the data to stories with specific tags. So far I haven't found a way to write the correct syntax to achieve this purpose. Here's an example of a standard query that I would include in the cardboardConfig:
var query = new rally.sdk.util.Query('SomeField = "Some Value"');
This works well enough when trying to query a field that contains a single value, but this doesn't appear to work on tags since tags are arrays -- assuming I am even referencing the correct field name. I tried all of the following without success:
var query = new rally.sdk.util.Query('Tags = "Some Value"');
var query = new rally.sdk.util.Query('Tags contains "Some Value"');
var query = new rally.sdk.util.Query('Tag = "Some Value"');
var query = new rally.sdk.util.Query('Tag contains "Some Value"');
var query = new rally.sdk.util.Query('Tags = {"Some Value"}');
var query = new rally.sdk.util.Query('Tags contains {"Some Value"}');
var query = new rally.sdk.util.Query('Tag = {"Some Value"}');
var query = new rally.sdk.util.Query('Tag contains {"Some Value"}');
var SearchTags = { "Some Value" };
var query = new rally.sdk.util.Query('Tags = SearchTags');
var SearchTags = { "Some Value" };
var query = new rally.sdk.util.Query('Tags contains SearchTags');
What is the correct field name and operator for filtering the data to specific tags?
Try this:
var query = new rally.sdk.util.Query('Tags.Name Contains "Some Value");
This works for tags, but won't currently work for all collections.