I have this code:
array ('id' => 1, 'name' => "Murka", 'date_of_birth' => "2014-10-31", "breed_id" => 1),
array ('id' => 1, 'name' => "Jurka", 'date_of_birth' => "2014-11-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Nyash", 'date_of_birth' => "2014-12-31", "breed_id" => 3),
array ('id' => 1, 'name' => "Meowy", 'date_of_birth' => "2014-01-31", "breed_id" => 4),
array ('id' => 1, 'name' => "Yummi", 'date_of_birth' => "2014-10-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Barss", 'date_of_birth' => "2014-05-31", "breed_id" => 2),
array ('id' => 1, 'name' => "Nonam", 'date_of_birth' => "2014-05-31", "breed_id" => null
I'll want to change all 'id' => 1 (except the 1st) so the number will increment by 1. It's simple to achieve with Emacs:
M-x replace-regexp
\(1,\)
\,(1+ \#),
As described here. After some research the maximum that I've been able to achieve with Vim is (inspired from here):
:let i=1 | g/1,/ s//\=i/ | let i+=1
But this removes all the following commas:
array ('id' => 1 'name' => "Murka", 'date_of_birth' => "2014-10-31", "breed_id" => 1),
array ('id' => 2 'name' => "Jurka", 'date_of_birth' => "2014-11-31", "breed_id" => 2),
array ('id' => 3 'name' => "Nyash", 'date_of_birth' => "2014-12-31", "breed_id" => 3),
array ('id' => 4 'name' => "Meowy", 'date_of_birth' => "2014-01-31", "breed_id" => 4),
array ('id' => 5 'name' => "Yummi", 'date_of_birth' => "2014-10-31", "breed_id" => 2),
array ('id' => 6 'name' => "Barss", 'date_of_birth' => "2014-05-31", "breed_id" => 2),
array ('id' => 7 'name' => "Nonam", 'date_of_birth' => "2014-05-31", "breed_id" => null),
So I have to fix it (I know it's easy).
I am aware of this and macros, I'm just interested to know if there any one-line command solution in Vim.
More general question: is it possible in Vim to inject some logic like conditional statements, manipulating on regex back references? The example for this in Emacs would be:
C-M-% \(^.*\)\(linear-gradient(\)\(to right\|to bottom\)\(.*$\) <RET>
\& C-q C-j
\1-prefix-\2\,(if (equal "to right" \3) "left" "top")\4
This one helped me about a year+ ago to refactor some huge scary HTML code that had a much of inline CSS.
I don't have an answer to your general question, but I do have one for your specific situation. You can make your command work by putting the comma into a positive look-ahead, like this:
:let i=1 | g/1(\,\)\#=/ s//\=i/ | let i+=1
Now it will only replace the 1.
A really easy solution:
:%norm f1s^R=line('.')^M
Obtained like this:
:%norm f1s<C-v><C-r>=line('.')<C-v><CR>
If you are not comfortable with typing complete macros on the command-line you can achieve the same result via recording:
qq
f1s<C-r>=line('.')<CR>
q
[range]#q
Another approach. go to the second line, put the cursor over the first 1, now start a visual block selection Ctrl-v, press j until the line you want increment and press g Ctrl-a
Related
I have a Classic Report with a schedule for each day. There are no, one or multiple entries per day. It looks like this:
select
week_no,
apex_item.DISPLAY_AND_SAVE(p_idx => 8, p_value => plan_id) as ID,
apex_item.select_list(p_idx => 1, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_1', p_value => monday) as monday,
apex_item.select_list(p_idx => 2, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_2', p_value => tuesday) as tuesday,
apex_item.select_list(p_idx => 3, p_list_values => 'S1;1,S2;2,S3;3', p_attributes => 'size="3" multiple="multiple"', p_show_null => 'NO', p_show_extra => 'NO', p_item_id => plan_id || '_3', p_value => wednesday) as wednesday
from plan;
I can select multiple values and can save them to my table. It gets save like this "1,2". But I can't load the data rows with multiple selected values.
I can select multiple options with jQuery like this
$('#1000_1').val(["1","2"]);
but I don't know how to select the stored values from table with PL/SQL and then set the options selected with javascript.
I tried to load the data in an apex_item.text (id="1000_11" for monday etc.) and transfer the values in "After Refresh" DA to select list like that:
var sel_opt = $('#1000_11').val();
if (sel_opt == "1,2")
{
$('#1000_1').val(["1","2"]);
}
else if (sel_opt == "1,3")
{
$('#1000_1').val(["1","3"]);
}
else if (sel_opt == "2,3")
{
$('#1000_1').val(["2","3"]);
}
else if (sel_opt == "1,2,3")
{
$('#1000_1').val(["1","2","3"]);
}
It works, but maybe there's a smarter solution?
I create a sample Workspace on https://apex.oracle.com/pls/apex/f?p=4550:1:0:::::
Workspace: multi_select
Username: dev
Password: newYears3problems
I would create SELECT LIST page items for each selection menu and set their multi selection option to Yes.
then I'm guessing I'd need something like this somewhere at my page-process section
declare
array apex_application_global.vc_arr2;
begin
array := apex_util.string_to_table (:P30_SELECT_LIST_1);
apex_collection.create_or_truncate_collection ('P30_SELECT_LIST_1');
apex_collection.add_members ('P30_SELECT_LIST_1', array);
end;
to store more than one menu item at once.
then I'd add something like that to my query
and ITEM_1 in (
select c001
from apex_collections
where collection_name = 'P30_SELECT_LIST_1'
)
I probably didn't understand your question, but according to part that I get, it's straightforward sql query. no need for js.
Is it possible to format both a row and column?
For instance I am doing a loop that uses the index to style rows different colors based on if it is even or odd but I also want to style a column that has percentages to use the :num_fmt => 9
Also why when I am presenting the number as something like 1.2 does that end up changing it to 120%, all I want is for that data to look like 1.2%
#people.each_with_index | person, index |
if index.odd?
sheet.add_row [person['name'], person['rate']]
else
sheet.add_row [person['name'],person['rate']], :style => even_row
end
end
(my even row style is set at the top of my code)
I figured this out, you need to do set your style using something like
percent = s.add_style(:num_fmt => 9)
even_row_percent = s.add_style(:bg_color => 'blue', :fg_color => 'white', :b => false, :format_code => 0%)
even_row = s.add_style(:bg_color => 'blue', :fg_color =>'white', :b => false)
then in your loop just use an each with index and then use a if statement like
if index.odd
sheet.add_row[
item[:value],
item[:value_percent]], :style => [nil, percent]
else
sheet.add_row[
item[:value],
item[:value]], :style => [even_row, even_row_percent]
end
I am trying to use the APEX data loader to allow users to import data and one of the column values I would rather not force the users to provide since the value is readily available in the session when the users selects import.Is there a way to add that column value programmatically?
With the Oracle APEX 4.2 data wizard, adding the rows to the SPREADSHEET_CONTENT is not enough if the First Rows are the column names. You also have to run the following assuming you are adding a 9th column, 'C009' and the name is 'MY_COLUMN_NAME'.
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'PARSE_COL_HEAD',
p_c001 => 'C009',
p_c002 => 'MY_COLUMN_NAME')
;
Otherwise, it just ignores the data as it's using the meta data of PARSE_COL_HEAD.
I had a similar issue and solved it along the lines that Greg suggested in his comment. Here is a sample of the code I used in the process that runs right after "Parse Uploaded Data" on page 1 of the wizard:
FOR UPLOAD_ROW IN (SELECT SEQ_ID
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '2',
p_attr_value => :P1_TABLE_FIELD_2);
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '3',
p_attr_value => :P1_TABLE_FIELD_3);
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '4',
p_attr_value => :P1_TABLE_FIELD_4);
END LOOP;
For a more detailed explanation see http://www.jrweth.com/oracle-apex-data-loader-part-1-adding-custom-columns/
You could edit the loader and add a data transformation rule.
I hate to just post a link but this blog post from Rowan provides ample explanation how this works since the documentation from Oracle does not.
Application Express Data Loader Transformation Rules in 4.2
Basically, the transformation rules feature allows you to select one or more columns in your target table. You then choose the type of transformation from the available options: PL/SQL expression, PL/SQL Function, SQL Query (2 types her).
The loader will run this function for each row loaded and you can reference session state, lookup values in other tables or package state, as well as column values in the row. For example if you have a column named COLUMN1 you would refer to it in the source of the transformation rule as :COLUMN1 (e.g IF :COLUMN1 > 10 THEN .... ).
If you use the PL/SQL Expression, the value after evaluation will be returned as the new column value. If you use PL/SQL Function you will need to add a RETURN expression to get this value back tot he column.
That is to say that you will not be able to set the values using the bind notation you use to get values. So if you want COLUMN1 to be set to 10, build a rule to set that value, don't try to do :COLUMN1 := 10; as this state will only last during the execution of your rule for the record being transformed.
This new code is working perfectly despite the USE_APPLICATION_DATE_FORMAT column added by APEX. Note that near the bottom of the code the p_seq is set to '35'.
Declare
v_date date;
BEGIN
SELECT SYSDATE INTO v_date FROM Dual;
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'PARSE_COL_HEAD',
p_c001 => 'C036',
p_c002 => 'UPLOAD_DTE');
APEX_COLLECTION.MOVE_MEMBER_DOWN(
p_collection_name =>'PARSE_COL_HEAD',
p_seq => '36');
FOR UPLOAD_ROW IN (SELECT SEQ_ID FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '35',
p_attr_value => v_date);
END LOOP;
END;
For Oracle APEX data loader 4.2, in the developer view, look on the 1st page, in the 'Page Processing' block, right click on "Processing" and select "add new process" , then name it. Mine is called 'add_column', then add the below code.
You need to first add a new column to the APEX collection. You can do APEX_COLLECTION.ADD_MEMBER() function. In the code below, I add in an additional column at column 31 location and the name of the column is called 'FILE_DATE'. This is the same as the name as the column the database table.
After that you loop through each row by SEQ_ID and update column 31 with a value. In my case, I wanted to get the filename, which was :P25_FILE_NAME
When you run the pages, you can click on 'Session' on the developer toolbar at the bottom to have a look at the APEX collection array and see if your column is getting populated correctly.
BEGIN
APEX_COLLECTION.ADD_MEMBER
(
p_collection_name => 'PARSE_COL_HEAD',
p_c001 => 'C031',
p_c002 => 'FILE_DATE');
FOR UPLOAD_ROW IN (SELECT SEQ_ID FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => '31',
p_attr_value => :P25_FILE_NAME
);
END LOOP;
END;
I am able to get through it using the code below:
Declare
v_count number(10);
BEGIN
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'PARSE_COL_HEAD',
p_c001 => 'SESSION_ID');
v_count:=APEX_COLLECTION.COLLECTION_MEMBER_COUNT ('PARSE_COL_HEAD');
v_count:=v_count+1;
FOR UPLOAD_ROW IN (SELECT SEQ_ID
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE (
p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => v_count,
p_attr_value => V('APP_SESSION')); –-I was trying to load session id
END LOOP;
END;
Declare
v_count number(10);
BEGIN
v_count:=APEX_COLLECTION.COLLECTION_MEMBER_COUNT ('PARSE_COL_HEAD');
v_count:=v_count;
APEX_COLLECTION.ADD_MEMBER( p_collection_name => 'PARSE_COL_HEAD',
p_c001 => concat('C00',v_count),
p_c002 => 'ID_OFFICE_LOCATION');
APEX_COLLECTION.MOVE_MEMBER_DOWN( p_collection_name =>'PARSE_COL_HEAD',
p_seq => v_count+1);
FOR UPLOAD_ROW IN (SELECT SEQ_ID
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'SPREADSHEET_CONTENT')
LOOP
APEX_COLLECTION.UPDATE_MEMBER_ATTRIBUTE ( p_collection_name => 'SPREADSHEET_CONTENT',
p_seq => UPLOAD_ROW.SEQ_ID,
p_attr_number => v_count,
p_attr_value => :P0_ID_OFFICE_LOCATION);
END LOOP;
END;
I am facing some problem related to getSendStatistics in Amazon SES Api, problem is that when i call getSendStatistics first time return data is not same as Second time call getSendStatistics (when page is refresh).
Example
First time return data
[GetSendStatisticsResult] => CFSimpleXML Object
(
[SendDataPoints] => CFSimpleXML Object
(
[member] => Array
(
[0] => CFSimpleXML Object
(
[DeliveryAttempts] => 3
[Timestamp] => 2013-04-23T04:47:00Z
[Rejects] => 0
[Bounces] => 0
[Complaints] => 0
)
[1] => CFSimpleXML Object
(
[DeliveryAttempts] => 1
[Timestamp] => 2013-04-23T10:17:00Z
[Rejects] => 0
[Bounces] => 0
[Complaints] => 0
)
)
)
)
Second time return data
[GetSendStatisticsResult] => CFSimpleXML Object
(
[SendDataPoints] => CFSimpleXML Object
(
[member] => Array
(
[0] => CFSimpleXML Object
(
[DeliveryAttempts] => 1
[Timestamp] => 2013-04-23T10:17:00Z
[Rejects] => 0
[Bounces] => 0
[Complaints] => 0
)
[1] => CFSimpleXML Object
(
[DeliveryAttempts] => 3
[Timestamp] => 2013-04-23T04:47:00Z
[Rejects] => 0
[Bounces] => 0
[Complaints] => 0
)
)
)
)
some how its change it position don't know what happening can any one guide me about this problem . i am newbie for Amazon SES
Thank You
According to AWS, there is no guarantee, at any particular moment, that statistics are 100% up to date - there may be a reporting lag, even if you haven't sent something in between the calls.
We may delay the data returned in GetSendStatistics in order to better aggregate the data, and it is not guaranteed to be accurate to the minute.
https://forums.aws.amazon.com/thread.jspa?messageID=278174
Could this possibly explain what you are seeing?
I need a regexp which does the following:
Heres the name of an HTML input field:
lm[0][ti]
I need to find the basic name ("lm"). Only if the name contains brackets I need to find the string in the second brackets ("ti").
To get it in portions is easy with the following regexp:
([a-zA-Z\d_]+)\[?([0-9]*)\]?\[?([a-zA_Z\d_]+)\]?
It matches all the portions I need.
Array
(
[0] => lm[0][ti]
[1] => lm
[2] => 0
[3] => ti
)
But if the HTML input name was just "lm", using this regexp I cannot determine that item #4 in the array is a valid name. The array would look like this:
Array
(
[0] => lm
[1] => l
[2] =>
[3] => m
)
"m" is not valid for me, I'd like to get this array:
Array
(
[0] => lm
[1] =>
[2] =>
[3] =>
)
or this
Array
(
[0] => lm
)
You can test the regexp here:
http://regexp-tester.mediacix.de/exp/regex/
Thanks for support in finding the right regexp...
Try this:
(\w+)(?:\[(\d+)\])?(?:\[(\w+)\])?
Input:
lm[0][ti]
Output:
Input:
lm
Output: