how to add fieldname as a variable in OCCI - c++

In the below C++ code, i am updating a field of emp table based on the search value. But this code is not working properly. I am getting output as aborted.
void UpdateData(string field_name,string updated_value,string search_value)
{
stmt->createStatement("UPDATE emp SET :1=:2 where search=:3");
stmt->setString(1,field_name);
stmt->setString(2,updated_value);
stmt->setString(3,search_value);
stmt->executeUpdate();
}
In my program user will select which field they have to update and the selected field name is passed into function as field_name parameter. updated_value is the new value entered by the user and search_value is the search key to find the appropriate record.
If i do like
stmt->createStatement("UPDATE emp SET field_name=:2 where search=:3");
its working..
But the problem is, the field name will change according to user selection. How i can overcome this problem. Is there any other way ?

You can't set the name of the field with the statement->setString() method; only the values of the variables can be bound like that.
I know of only two solutions to achieve this (both aren't particularly nice):
Dynamically create the statement string
string statement ="UPDATE emp SET " + fieldname + "=:1 where search=:2";
Prepare individual statements, each affecting one field and choose at runtime
const string STATEMENT_FIELD_CITY = "UPDATE emp SET CITY=:1 where search=:2";
const string STATEMENT_FIELD_LAND = "UPDATE emp SET LAND=:1 where search=:2";

Related

Oracle Apex Autocomplete Item to return ID value, not the lookup value

I have the table "SYMPTOMS" with two fields:
"ID" number and "SYMPTOM" varchar2(1000).
I want on my page the item "P2117_SYMPTOM_ID" to be autocomplete and search from the second field ("SYMPTOM") but to return the ID value of this record.
Check the docs. The page item type "Text field with autocomplete" only takes a single column as source (a return value), not 2 columns like a list of values. Reason is that this is an enhanced text field: you can freely enter data but it will suggest you possibilities from a list. A text field only has its actual value as return type too. You could have return ids from a table but then how would you handle values entered by the user that are not in the list ? If you want to map the data the user enters to an id then you can write your own function to do that. Ideally that function would:
Return the id of the value if it exists
Create a new value and return that newly created id if it doesn't exist.

How to create a field with a list of choices but store the index?

I'm making a Microsoft Access table where one of the fields is a list of pre-made options. When I make a SQL query on that table it returns the values of the list as strings containing the spelled out choice. I would like to assign numerical values to each element of the list so a SQL query returns a number instead. How do I do this? I know it's possible because I have an access file with such a list but I'm unable to recreate it.
An easy way to do this is to have your combo box use a query of the table as a Rowsource. This query would have the table unique ID in the first field and the field you wish to return as the second field. Then change the setting on the combo box for "Column Count" to 2. If you want to show both fields change the "Column Widths" value to 1"; 1". If you want to show only one field, change the value of one you do not want to see to 0. Now we you refer to this list in an SQL queries, it will use the ID field but show the user the string field.

How do i can create IR in apex oracle based on different table and column

IR based on PL/SQL Function Body returning SQL Query.
How do i can create Interactive reports based on multiple table and Deferent column name.
Exp :-
Select list item return three value
1 or 2 or 3
And the function return query basen on select list value
when Value equal 1
Select name, satate, country_id from cities
when value equal 2 Return
Select country, id from country
when value equal 3 Return
Select ocean,oc_id,from oceans
The three query return different column name and value.
Ok firstly, your question is poorly written. But from what I gather, you want an SQL query that returns different things based on an input.
I dont think you even need a plsql function body for this.
Simply do something like this:
SELECT * FROM
(SELECT name as name,
state as state,
country_id as id,
1 as value
FROM cities
UNION ALL
SELECT country as name,
NULL as state,
id as id,
2 as value
FROM country
UNION ALL
SELECT ocean as name,
NULL as state,
oc_id as id,
3 as value
FROM oceans)
WHERE value = :input_parameter_value;
Because if you are trying to display a variable number of columns and constantly changing their names and such. You are gonna have a bad time, it can be done, as can everything. But afaik its not exactly simple
No objections to what #TineO has said in their answer, I'd probably do it that way.
Though, yet another option: if your Apex version allows it, you can create three Interactive Report regions on the same page, each selecting values from its own table, keeping its own column labels.
Then create a server condition for each region; its type would be Function that returns a Boolean and look like
return :P1_LIST_ITEM = 1;
for the 1st region; = 2 for the 2nd and = 3 for the 3rd.
When you run the page, nothing would be displayed as P1_LIST_ITEM has no value. Once you set it, one of conditions would be met and appropriate region would be displayed.

APEX dynamic tabular form field types

We are populating a subregion of a page with an Iframe (call to another page) with data for a questionnaire.
We have PAGE ITEM variables (:P37_... populated by query) that contain table values for P37_QUESTION_DESCRIPTION and P37_RESPONSE_TYPE.
The sub page used in the region (:P28_...) assigns report attributes for each column... where We populated the question text in the P28_QUESTION_DESC and a Y/N Select List defined list of values in the P28_RESPONSE_DESC_DISPLAY column. This works fine.
Now, the P37_RESPONSE_TYPE can more than just this Y/N Select List. It could be TEXTAREA, PICKLIST, DATE...
How can we define the :P28_RESPONSE_DESC_DISPLAY column dynamically to be any number of user input field types (based on the value in :P37_REPSONSE_TYPE?)
This was solved by using a non-tabular form report generated by query using apex.item functions. But is has left me with another problem. Here's the query:
select
apex_item.hidden(31,CASE_QUEST_DTL_ID) CASE_QUEST_DTL_ID,
apex_item.hidden(32,CASE_MGMT_BASE_ID) CASE_MGMT_BASE_ID,
apex_item.display_and_save(33,to_number(question_seq_no)) QUESTION_SEQ_NO,
apex_item.display_and_save(34,question_desc) QUESTION_DESC,
case when response_type = 'PICKLIST-YESNO' then apex_item.select_list_from_lov(35,response_desc,'YES_NO_SELECTLIST',NULL,'NO')
when response_type = 'TEXTFIELD' then apex_item.text(35,response_desc)
when response_type = 'TEXTAREA' then apex_item.textarea(35,response_desc,5,40)
when response_type = 'DATEPICKER' then APEX_ITEM.DATE_POPUP2(35,to_date(response_desc,'dd-mon-yyyy'),'dd-mon-yyyy')
end RESPONSE_DESC
from V_CASE_QUEST_LINK
where question_set_code like 'COB_Q%'
and case_mgmt_base_id = :P37_CASE_MGMT_BASE_ID
My problem is now grouping the questions by question_set_code. Because GROUP BY is evaluated after the select, it cannot simply be tacked on to the end of the query. I'm not sure that using a nested select will work here because of the apex.item calls. Anyone have a suggestion on how I can group these questions by the column?

Updating SharePoint field links

I used a piece of code that retrieves a field link for a specified content type and sets the field to either required or not required. This works fine but when I try to do the same for a field that has spaces in the name, the code throws an error.
SPField col = //some column retrieved from a list
SPContentType ct = col.ParentList.ContentTypes["MyContentTypeName"] //gets the content type
SPFieldLink fieldLink = ct.FieldLinks["MyFieldname"]; // gets the fieldLink
ct.Update();
It works if MyFieldName is a string like "Hobbies" or "Amount", but fails if it's a string like "Full Name".
Is there a workaround?
You are probably using the field display name instead of the field internal name
Have you tried:
"Full_x0020_Name" ?