Using a session variable in the where clause of a LINQ statement - linq

Good afternoon all.
I have a page that displays data in a gridview based upon what the user selects for a material in a radiobutton list and how many they wish to see, a text box.
Upon logging into this page, a session variable for MemberID is created, MemberKey.
What I would like to do is pass this session variable into the LINQ statement so that only the specific member that has logged in sees their data:
ContextTypeName="VDSWeightsReportingService.CompleteWeightsDataContext" EnableInsert="True"
EnableUpdate="True" TableName="tblOnlineReportingCOMPLETEWEIGHTSFINALDEMOs"
Where="MaterialText == #MaterialText && Productpriority <= #Productpriority && MemberId == #MemberId">
<WhereParameters>
<asp:ControlParameter ControlID="radMaterial" Name="MaterialText"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="tbxHowMany" Name="Productpriority"
PropertyName="Text" Type="Int32" />
<asp:SessionParameter Name="MemberId" SessionField="MemberKey"
Type="String" />
</WhereParameters>
</asp:LinqDataSource>
I have tried to insert the session variable as above but without the LINQ no longer seems to go through the motions.
Can someone point out to me where I am going wrong?
If this doesn't work, or is not possible, can someone advise of a way around this? i.e. using this session variable in the LINQ where clause.

Make sure you select the correct session variable!!!!

Related

ADF_FACES-60097

I am creating a school management application using Oracle ADF. I have one Student Result page where we can add the result for each student. Here is the image of the same:
Student's Result Page
When I change say the Result Year, I get an exception like:
<oracle.adf.view> <_logUnhandledException> <ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase UPDATE_MODEL_VALUES 4>
oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:java.lang.Integer from type:java.lang.String with value:Pass
Don't Understand this only the student id is number, all other 3 attributes are string only.
Can anyone help?
Below is the Jsff Code:
<af:column sortProperty="#{bindings.ResultStudentResultView.hints.ResultYear.name}"
filterable="true" sortable="true"
headerText="#{bindings.ResultStudentResultView.hints.ResultYear.label}"
id="c7">
<af:selectOneChoice value="#{row.bindings.ResultYear.inputValue}"
label="#{row.bindings.ResultYear.label}"
required="#{bindings.ResultStudentResultView.hints.ResultYear.mandatory}"
shortDesc="#{bindings.ResultStudentResultView.hints.ResultYear.tooltip}"
id="soc2">
<f:selectItems value="#{row.bindings.ResultYear.items}" id="si2"/>
<f:validator binding="#{row.bindings.ResultYear.validator}"/>
</af:selectOneChoice>
</af:column>
This error is with the column Result, check what is the attribute type in view object and if corresponding default value is given as literal.

Book an event page

I need to setup A form where a user would be signing up to an event but while doing that it will collect the data of the user from their database table automatically while also taking information from the events table and inserting it into another table
What are you using primarily to achieve this at the moment? Are you using PHP? In case of PHP,
if you have a user id on whichever user that is going to fill out the form, then you can use that user id to fetch the information from whatever table that you need, and retrieve the information of the user. You then put those into PHP variables for later use. The only way to know which user is which, is by using sessions. This session can be their user id, which I will go by in this example, simply because it's simple and easy.
The handling of form data can be done by a classic form tag with post method and a submit button. You tell the form whichever page it is to supposed to post to.
It can also be handled by AJAX.
You then put those posts into PHP variables, or use them directly, but I personally prefer to put them into variables for clarification. It can look a bit messy using the post variables directly into your query, as well as the security risks it involves.
What it could look like is something like this:
<?php
/*
Firstly we need our session (this should be set upon logging by using $_SESSION['userId'].
As mentioned before, I am using a user id as our session variable in this example.
*/
/*
Carry over the session.
Use session_start() before anything else in a file to get the session of a user.
*/
session_start();
//Put session into a php variable
//mysql_ syntax:
$userId = mysql_real_escape_string($_SESSION['userId']);
mysqli_ syntax, with $conn being your database connection variable:
$userId = mysqli_real_escape_string($conn, $_SESSION['userId']);
mysqli_ syntax, with $conn being your database connection variable:
$userId = mysqli_real_escape_string($conn, $_SESSION['userId'])
?>
Now what is left, is to construct our form and send that data. Since I personally would prefer to handle the data in another file than the file that contains the form, we're going to tell the form to post to another file. This file will contain our form data, as well as our user data. How we will go by getting our user data is by using the session variable, which conveniently happens to be the user id (which is unique to every user). We can post this with everything else in our form by using a hidden input field carrying the user id variable (just as an example).
<!--
What we do here is make a form that that tells which page it is going to go to
on submit
-->
<form action="/another_page.php" method="POST">
<!-- Our hidden input field, carrying the user id -->
<input type="hidden" name="userId" value="<?php echo $userId; ?>" />
What brand is your current car?:<br />
<input type="text" name="carBrand" placeholder="Brand of your car" />
Tell us a little about yourself:
<textarea rows="4" cols="50" name="summary"></textarea>
Rate your experience, 1-5:
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br /><br />
<button type="submit" name="submitButton">Submit form!</button>
</form>
Now we go to the other file to handle our data, which we will later put into the second table as per your request.
<?php
//This is our POST variables from our form:
$userId = $_POST['userId'];
$car_brand = $_POST['carBrand'];
$summary = $_POST['summary'];
$rating = $_POST['rating'];
//Now to our SQL, to get there data of our user:
//Put SQL command into a variable
$sql = "SELECT * FROM name_of_user_table WHERE userId='$userId'";
//Put query into a variable with mysql_ syntax:
$result_set = mysql_query($sql);
//Put query into a variable with mysqli_ syntax:
//$conn still being your connection variable
$result_set = mysqli_query($conn, $sql);
//The rows in your table in mysql_ syntax:
$row = mysql_fetch_array($result_set);
//The rows in your table in mysqli_ syntax:
$row = mysqli_fetch_array($conn, $result_set);
/*
Now we can start using our data from the database, and store them into variables.
The variables depends on your fields names in the database.
We basically have the data stored into an array,
where we need to tell the array exactly which index we'd like to use
(in this case which field we'd like to store into a variable).
*/
//Examples:
$variable1 = $row['name_of_field'];
$variable2 = $row['name_of_another_field'];
[...]
?>
Now what is left, is to put everything into your second table, using our variables. Hope this helps :)
It is also very important that you use prepared statements before firing your SQL commands into your database, or at least sanitize the inputs to prevent SQL-injections.
Martin wrote a really comprehensive answer; I'm not saying that it is wrong (how could I? I don't speak PHP); however, as the OP tagged it as Oracle Application Express (not PHP), it might not be the best fit.
Anyway: that looks like a simple task: if signing up to the event is done by pushing a button (why wouldn't it be?), you'd create a process which does the rest of the job. Either write it in the appropriate process property, or create a stored procedure which collects data & inserts it elsewhere and - in the Apex process - call that procedure.

Odoo. I'd like to make invisible the record in tree view, depending value of one field

Openerp, Odoo question.
I'd like to hide the row in tree view depending one field (e.g. item is not in stock).
Maybe I need to put this somewhere in tree_view.xml:
attrs="{'invisible': [('in_stock','=', 0)]}"
It would be fine, if this works, like the res_partner 'Active' flag
When 'Active' field is False, all record is disappeared.
Any advice would be appreciated!
If you want to hide the record completely than use this domain in the window action. To show only the records that matches the domain.
<field name="domain">[('in_stock', '=', 0)]</field>
You can hide using the following syntax:
<field name="flag" invisible="1"/>
<field name="x" attrs="{'invisible': [('flag','=', False)]}"/>
Here flag should be a computed field which computes the stock of current item.
so in script just make the field as:
flag = fields.Boolean("String", compute="get_stock_status")
def get_stock_status(self):
# do your computation and change values of flag accordingly
self.flag = False

Coldfusion and session variable not setting

I have a survey form with 5 ques, there is one question on each page and user clicks through them with next button on the page. Now, the user is not logged in, I want to set a session variable only when the user takes the first ques on form and clicks next. But I am getting userid not defined in session for the line 2. I am not really sure what I am doing wrong here. Can anyone suggest if they see what is going on. I don't want to be creating multiple userids every time he hits next button. Thanks
<cfif structKeyExists(FORM, "user_mode") and form.user_mode EQ "next">
<cfif NOT ( StructKeyExists(session,userid) )>
<cfquery name="insertuser" datasource="#application.datasource#">
INSERT INTO survey_user(ip_address)
VALUES (<cfqueryparam cfsqltype="cf_sql_varchar" value="#CGI.REMOTE_ADDR#" />)
</cfquery>
</cfif>
</cfif>
StructKeyExists(session,userid)
should be:
structKeyExists( session, 'userid' )
Note the quotes. Without them it's looking for the variable "userid" rather than the key name "userid".

How to execute a function that returns an Oracle UDT (User data type) in WSO2 DSS?

I've tried with:
select package.faunction(param1,param2...paramX) as "data" from dual.
Works like a charm. Then, I´ve got the output result with:
element column="data[0]" name="name1" xsdType="string"
element column="data[1]" name="name2" xsdType="string"
And that works too. But when the output has more than 10 columns I've got an exception
Cannot find parameter with type:column name:data[10] DS Code: INCOMPATIBLE_PARAMETERS_ERROR
Any idea what I can do to make this work with more than 10 parameters?
PS: If I use the same query with the "User column numbers" option checked and <element column="1" name="result" xsdType="string"/> as output mapping WORKS, but all the UDT came in just one column.

Resources