How to delete the fist 10 recods from a table ? The problem is real.
Hi,
the code below shows that deleting a records using a cursor works well, if your table is out of a environment, but if you are using a environment the things goes different. Please help me, what i am doing wrong ?
This code is the most clean code i now to do.
// THE CODE (BEGIN).
// BDBTEST.cpp : Clean code.
#include "X:\include\berkeleydb\db_cxx.h"
#define DWORD unsigned long int
#define UINT unsigned int
#define DB_ENV_PATH "Z:\\Test"
#define DB_FULL_NAME "Z:\\Test\\Test.db"
typedef struct STRTEST
DWORD dwID;
char caTxt[64];
} strTest;
// Functions.
int compare_int ( Db *dbp,
const Dbt *a,
const Dbt *b);
void Save();
void Load();
void DeleteAll();
// Global variables.
DbEnv *g_penvDbEnv;
Db *g_pdbTest;
Dbc *g_pdbcCursor;
Dbt g_dbtTestKey;
Dbt g_dbtTestData;
UINT g_ui32ENVOpenFlags;
char g_caError[256];
int g_iResult;
// Main function.
int main(int argc, char* argv[])
g_penvDbEnv = NULL;
g_pdbTest = NULL;
// First we run without environment (NO ERROR USING g_pdbcCursor->Del(0)).
remove(DB_FULL_NAME);
Save();
Load();
DeleteAll();
Load();
// Now we run with environment ("Dbc::del: Invalid argument" (err_ = 22) - ERROR USING g_pdbcCursor->Del(0)).
try
g_penvDbEnv = new DbEnv(0);
if(g_penvDbEnv == NULL)
return 0;
catch(DbException &e)
sprintf(g_caError, "ERRO -> DSDBBD: %s\n", e.what());
return 0;
// Set the normal flags for a transactional subsystem. Note that
// we DO NOT specify DB_RECOVER.
g_ui32ENVOpenFlags = DB_CREATE | // If the environment does not exist, create it.
DB_INIT_LOCK | // Initialize locking.
DB_INIT_LOG | // Initialize logging.
DB_INIT_MPOOL | // Initialize the cache.
DB_THREAD | // Free-thread the env handle.
DB_INIT_TXN; // Initialize transactions.
// Open/Create environment.
try
// Environment settings.
g_iResult = g_penvDbEnv->set_encrypt("1234", DB_ENCRYPT_AES);
g_iResult = g_penvDbEnv->set_lg_bsize (1024 * 256); // LOG MEMORY FILE MAX SIZE.
g_iResult = g_penvDbEnv->set_cachesize(0, 1024 * 512, 0);
g_iResult = g_penvDbEnv->set_flags (DB_AUTO_COMMIT, 1);
g_iResult = g_penvDbEnv->set_flags (DB_LOG_AUTOREMOVE, 1);
g_iResult = g_penvDbEnv->set_lg_max (1025 * 1024); // LOG FILE MAX SIZE.
// Open the environment with full transactional support.
g_iResult = g_penvDbEnv->open(DB_ENV_PATH, g_ui32ENVOpenFlags, 0);
catch(DbException &e)
sprintf(g_caError, "ERRO -> DSDBBD: %s\n", e.what());
return 0;
remove(DB_FULL_NAME);
Save();
Load();
DeleteAll(); // Error goes here.
Load();
g_penvDbEnv->close(0);
delete g_penvDbEnv;
g_penvDbEnv = NULL;
return 0;
void Save()
int i;
int iResult;
DWORD dwID;
strTest sttTest;
if(g_penvDbEnv == NULL)
g_pdbTest = new Db(NULL, 0);
else
g_pdbTest = new Db(g_penvDbEnv, 0);
// Setting databases flags (Just use with environment).
g_pdbTest ->set_flags(DB_CHKSUM | DB_ENCRYPT);
if(g_penvDbEnv == NULL)
g_pdbTest ->set_encrypt("1234", DB_ENCRYPT_AES);
g_pdbTest->set_bt_compare(compare_int);
g_iResult = g_pdbTest->open(NULL, DB_FULL_NAME, NULL, DB_BTREE, DB_CREATE | DB_THREAD, 0);
dwID = 1;
for(i=0;i<100;i++)
sttTest.dwID = dwID;
sprintf(sttTest.caTxt, "ID = %04u", sttTest.dwID);
g_dbtTestKey .set_data((void*) &sttTest.dwID);
g_dbtTestKey .set_size(sizeof(DWORD));
g_dbtTestData .set_data((void*) &sttTest);
g_dbtTestData .set_size(sizeof(sttTest));
iResult = g_pdbTest->put(0, &g_dbtTestKey, &g_dbtTestData, DB_NOOVERWRITE);
dwID++;
g_pdbTest->sync(0);
g_pdbTest->close(0);
delete g_pdbTest;
g_pdbTest = NULL;
void Load()
strTest *psttTest;
if(g_penvDbEnv == NULL)
g_pdbTest = new Db(NULL, 0);
else
g_pdbTest = new Db(g_penvDbEnv, 0);
// Setting databases flags (Just use with environment).
g_pdbTest ->set_flags(DB_CHKSUM | DB_ENCRYPT);
if(g_penvDbEnv == NULL)
g_pdbTest ->set_encrypt("1234", DB_ENCRYPT_AES);
g_pdbTest->set_bt_compare(compare_int);
g_iResult = g_pdbTest->open(NULL, DB_FULL_NAME, NULL, DB_BTREE, DB_CREATE | DB_THREAD, 0);
// Get a cursor
g_pdbTest->cursor(NULL, &g_pdbcCursor, 0);
// Iterate over the database, retrieving each record in turn.
while((g_iResult = g_pdbcCursor->get(&g_dbtTestKey, &g_dbtTestData, DB_NEXT)) == 0)
// Get temp struct.
psttTest = (strTest*) g_dbtTestData.get_data();
g_pdbcCursor->close();
g_pdbTest->close(0);
delete g_pdbTest;
g_pdbTest = NULL;
void DeleteAll()
strTest *psttTest;
try
if(g_penvDbEnv == NULL)
g_pdbTest = new Db(NULL, 0);
else
g_pdbTest = new Db(g_penvDbEnv, 0);
// Setting databases flags (Just use with environment).
g_pdbTest ->set_flags(DB_CHKSUM | DB_ENCRYPT);
if(g_penvDbEnv == NULL)
g_pdbTest ->set_encrypt("1234", DB_ENCRYPT_AES);
g_pdbTest->set_bt_compare(compare_int);
g_iResult = g_pdbTest->open(NULL, DB_FULL_NAME, NULL, DB_BTREE, DB_CREATE | DB_THREAD, 0);
// Get a cursor
g_pdbTest->cursor(NULL, &g_pdbcCursor, 0);
// Iterate over the database, retrieving each record in turn.
while((g_iResult = g_pdbcCursor->get(&g_dbtTestKey, &g_dbtTestData, DB_NEXT)) == 0)
// Get temp struct.
psttTest = (strTest*) g_dbtTestData.get_data();
g_iResult = g_pdbcCursor->del(0);
catch (DbException &dbe)
sprintf(g_caError,
"%s",
dbe.what());
g_pdbcCursor->close();
g_pdbTest->close(0);
delete g_pdbTest;
g_pdbTest = NULL;
int compare_int(Db dbp, const Dbt a, const Dbt *b)
int iReturn;
DWORD dwKey1;
DWORD dwKey2;
dwKey1 = 0;
dwKey2 = 0;
iReturn = 0;
dwKey1 = *((DWORD*) a->get_data());
dwKey2 = *((DWORD*) b->get_data());
if(dwKey1 > dwKey2)
iReturn = 1;
else
if(dwKey1 < dwKey2)
iReturn = -1;
return iReturn;
// THE CODE (END).
Thanks,
DelNeto
Hi all
I solved it. No documentation about it, but the solution is to use transaction.
Just use this DeleteAll function that all works fine.
void DeleteAll()
strTest *psttTest;
DbTxn *pTxn;
try
pTxn = NULL;
g_pdbTest = NULL;
if(g_penvDbEnv == NULL)
g_pdbTest = new Db(NULL, 0);
else
g_pdbTest = new Db(g_penvDbEnv, 0);
// Setting databases flags (Just use with environment).
g_pdbTest ->set_flags(DB_CHKSUM | DB_ENCRYPT);
if(g_penvDbEnv == NULL)
g_pdbTest ->set_encrypt("1234", DB_ENCRYPT_AES);
g_pdbTest->set_bt_compare(compare_int);
g_iResult = g_pdbTest->open(NULL, DB_FULL_NAME, NULL, DB_BTREE, DB_CREATE | DB_THREAD, 0);
if(g_penvDbEnv == NULL)
g_pdbTest->cursor(NULL, &g_pdbcCursor, 0);
else
// Get a cursor.
g_penvDbEnv->txn_begin(NULL, &pTxn, 0);
g_pdbTest->cursor(pTxn, &g_pdbcCursor, 0);
// Iterate over the database, retrieving each record in turn.
while((g_iResult = g_pdbcCursor->get(&g_dbtTestKey, &g_dbtTestData, DB_NEXT)) == 0)
// Get temp struct.
psttTest = (strTest*) g_dbtTestData.get_data();
g_iResult = g_pdbcCursor->del(0);
g_pdbcCursor->close();
if(g_penvDbEnv != NULL)
pTxn->commit(0);
catch (DbException &dbe)
sprintf(g_caError,
"%s",
dbe.what());
g_pdbcCursor->close();
if(g_penvDbEnv != NULL)
pTxn->abort();
g_pdbTest->close(0);
delete g_pdbTest;
g_pdbTest = NULL;
Thanks to all readers,
DelNeto
Similar Messages
-
How to delete some of records from wf_notifications table any API Name?
Hi All,
I want to delete some of records from wf_notifications table , can any one tell API' name and Back end delete process.
Thanks,
Ramu
Edited by: Ramu on Mar 20, 2013 5:42 AMHi ,
I hv done below script, now it's working fine.
DECLARE
CURSOR csr_transaction_id IS
SELECT hat.transaction_id,
hat.item_type,
hat.item_key,
ppx.employee_number,
hat.section_display_name
FROM hr_api_transactions hat, per_people_x ppx
WHERE hat.process_name = 'HR_PERSONAL_INFO_JSP_PRC'
AND hat.selected_person_id = ppx.person_id
AND ppx.employee_number IN
('100024773',
'100024820',
'100024859',
'100024879',
'100024902',
'100024937',
'100025137',
'100026470',
'610014755',
'610017039')
order by ppx.employee_number;
BEGIN
dbms_output.put_line('***Deleted all Transactions and Notifications of below Employee Personals Tranactions ***');
FOR my_cur_v IN csr_transaction_id
LOOP
/*Delete all Transaction_id's in hr_api_transactions,hr_api_transaction_steps,hr_api_transaction_values and hr_api_transaction_steps_bk tables */
hr_transaction_swi.delete_transaction
p_transaction_id =>my_cur_v.transaction_id,
p_validate => hr_api.g_false_num
wf_engine.abortprocess (
itemtype => my_cur_v.item_type,
itemkey => my_cur_v.item_key
/* Deleted all Notification_id's and item_key's in wf_item_activity_statuses,wf_items,wf_item_attribute_values,wf_notifications Table */
wf_purge.items (
itemtype => my_cur_v.item_type,
itemkey => my_cur_v.item_key
dbms_output.put_line('Emp No --'||my_cur_v.employee_number||'Transaction_id :'||my_cur_v.transaction_id||'Emp Personal Info :'||my_cur_v.section_display_name||
'Item Type :'||my_cur_v.item_type|| 'Item Key :'||my_cur_v.item_key);
END LOOP;
commit;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('hr_transaction_swi.delete_transaction api goest to exception block' ||sqlcode|| ' '||sqlerrm);
END;
/thanks,
Ramu -
How to delete a selected row from adf table
Hi
I am using a ADF Table to get data from the database, i need to select a specific row and then delete it how to get
this done.
Thanks in Advance.Or try this code:
In your backing bean:
public void deleteRows(ActionEvent actionEvent) {
((AppModuleImpl)getApplicationModuleForDataControl()).deleteRowEmp();
public static Object resolveExpression(String expression)
try
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression, Object.class);
return valueExp.getValue(elContext);
catch (Exception e)
;// log you message here
return null;
* Get application module for an application module data control by name.
* @param name application module data control name
* @return ApplicationModule
public static ApplicationModule getApplicationModuleForDataControl()
return (ApplicationModule) resolveExpression("#{data.AppModuleDataControl.dataProvider}");
}In your AppmoduleImpl:
public void deleteRowEmp(){
this.getEmpView1().removeCurrentRow();
this.getDBTransaction().commit();
}And another option is to expose the appmodule method as a client and bind to the jspx as a button. -
How to delete an .xml file from xmltype table?
Hi expert,
I am in I am in Oracle Enterprise Manager 11g 11.2.0.1.0.
SQL*Plus: Release 11.2.0.1.0 Production on Tue Feb 22 11:40:23 2011
I have inserted 3 .xml files into an xmltype table: DOCUMENT
SQL> SELECT OBJECT_VALUE FROM document;
OBJECT_VALUE
<?xml version="1.0" encoding="WINDOWS-1252"?>
<?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc
ation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd" classCode="DOC">
<id root="5ca4e3cb-7298-4948-8cc2-58e71ad32694"/>
<code code="51725-0" c
<?xml version="1.0" encoding="WINDOWS-1252"?>
<?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc
ation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd" classCode="DOC">
<id root="03d6a2cd-fdda-4fe1-865d-da0db9212f34"/>
<code code="51725-0" c
<?xml version="1.0" encoding="WINDOWS-1252"?>
<?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc
ation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd" classCode="DOC">
<id root="09ff06d6-8b85-43dd-b5cc-e22d00f02bd0"/>
<code code="51725-0" c
I tried to delete one xml file which with id root="03d6a2cd-fdda-4fe1-865d-da0db9212f34'
delete from DOCUMENT
where xmlexists('$p/document/id[@root="03d6a2cd-fdda-4fe1-865d-da0db9212f34"]'PASSING OBJECT_VALUE AS "p");
but failed.
Is there any expert can help?
Thanks a lot!
Cow
Edited by: Cow on Mar 11, 2011 7:02 PMHi,
Namespace issue.
You have to declare it in the XQuery prolog :
DELETE FROM document
WHERE XMLExists( 'declare default element namespace "urn:hl7-org:v3"; (::)
$p/document/id[@root=$root_value]'
passing object_value as "p",
'03d6a2cd-fdda-4fe1-865d-da0db9212f34' as "root_value" )
; -
How to delete the duplicate data from PSA Table
Dear All,
How to delete the duplicate data from PSA Table, I have the purchase cube and I am getting the data from Item data source.
In PSA table, I found the some cancellation records for that particular records quantity would be negative for the same record value would be positive.
Due to this reason the quantity is updated to target but the values would summarized and got the summarized value of all normal and cancellation .
Please let me know the solution how to delete the data while updating to the target.
Thanks
Regards,
SaiHi,
in deleting the records in PSA table difficult and how many you will the delete.
you can achieve the different ways.
1. creating the DSO maintain the some key fields it will overwrite the based on key fields.
2. you can write the ABAP logic deleting the duplicate records at info package level check with the your ABAPer.
3.you can restrict the cancellation records at query level.
Thanks,
Phani. -
How to delete a line item from the sales order
Hi all,
how to delete a line item from the sales order for which the production is already happened and it has been delivered. the production order status is DLV.
Regards
KumarHi
U can do this in two ways one u can short close the order by entering Reason for rejection in VA02 at header level and if yr order is multiple line item order u can enter the reason for rejection in any of the line item which u don't want to deliver.
This is called short close ( as the qty is not delivered fully).
Thx. -
PI 7.1 How to delete a published service from the service registry?
Hello,
I have the same problem in the pi 7.1, like Rahul in CE (Composition Environment) with the deleting of published services.
How to delete a published service from the service registry?
In the WS navigator I found only this operation:
deleteClassificationSystemValues and deleteClassificationSystem
I miss the operation deleteService.
Have you an idea?
Bye
StefanHi all,
I have opened an oss message and now I have an answer:
Use this Service: ServicesRegistrySiService and the operation deleteServices with the logical key of the service as parameter.
The logical key can be seen from the SR UI in the details of the endpoints.
Bye
Stefan -
How can delete my iphone5 data from the date its restored?
how can delete my iphone5 data from the date its restored?
it's unclear what you mean
if you wish to remove your iphone5 data you connect it to iTunes on the computer and click the restore button and choose restore to factory defect -
How to delete an old network from the list on the iPad?
Anyone know how to delete an old network from the listing and then add a new one? I did it when I first got my iPad and cannot remember how I did it! Hey, I'm an Apple rookie but I am trying. Take care and thanks in advance for any help.
Setting > General > Reset > Network Reset
-
How to delete 100+ released requests from the import queue?
Hello
How to delete 100+ released requests from the import queue?
One by one or there is more convinient way?
ThanksTo delete multiple non-imported transport requests, you do the following while in the import queue on STMS:
1) Highlight the status field of the import queue.
2) Sort the import queue by the status.
3) Put your cursor on the first non-imported transport, right-click, and click on Select Block.
4) Scroll down and put your cursor on the last non-imported transport, right-click and click on Select Block. This will highlight all requests from the first one selection to the last one selected.
5) Go to menu option Request > Delete.
If all of the requests in the import queue haven't been imported (no imported, including failed import, requests), you can jump to Steps 3-5. -
How to delete string or line from unix file(dataset) of application server
Hi All,
After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
I have tried for single record than also the file generates the last line(2nd line) also a blank line.
When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
How to delete string or line from unix file(dataset) of application server?
Please give your comments to resolve this.
Thanks
Tirumula Rao ChinniHi Rio,
I faced similar kind of issue working with files on UNIX platform.
The line is a line feed to remove it use
DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf.
DATA : lv_carr_return TYPE char1,
lv_line_feed TYPE char1.
lv_line_feed = lv_carr_linefd(1).
lv_carr_return = lv_carr_linefd+1(1).
Note: IMP: The character in ' ' is not space but is a special
character set by pressing ALT and +255 simultaneosly
REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '. -
How to delete a single request from DSO in BI 7.0
Dear Experts,
Could you please tell me how to delete a single request from DSO?
I mean, in DSO if we delete one request it also delete the requests which are above it. But i don't to delete the above it.
Please suggest me this issue.
Regards,
PrathapIN DSO--its a very basic thing....
ACTIVE TABLE and CHANGELOG tables are overwritten after activation of each request.
So ,each new request has a realationsip with the older request.
So in the cases:
1.If you activate the older request it will delete the new one ,because changelog entries have been written from the data of new request on the basis of the older one.
e.g older request entries:
a x 1
new request
a x 2
change log
a x 1
a x -1
a x 2
so its quite obvious you can't have a x 2 directly (because in the infocube you will be sending wrong entries by deleting the just the older request and loadning new request).
2.If you have activate new and old request toghterh then also system will not allow you to delete the newer request alone and you will have to delete both the requests.
I guess already someone proposed correct solution to you ...thats selective deletion...but rahter than doing selective deletion there is a better way if you want to cancel out a particular request:
thats request reverst posting
IN the process monitor of any particular request you can find out the option for request reverse posting..Its good for individual request cancellation(keyfig values will become 0 for that particular request)
regards,
rk -
Does anyone know how to delete credit card details from an Apple account?
Hi not sure if this is posted in the right place but i'll give it a go anyway.
Would anyone know how to delete credit card details from an Apple account?
Someone posted selecting 'none' in the payment section would work but i logged into my account online on a computer there aren't any options at all to do this.
I tried hitting edit but there isn't a delete button.
If anyone knows any help would be most appreciated!
-FAnswer should be here:
https://discussions.apple.com/message/12832322#12832322 -
How to delete backend system data from GRC,GRC 10 AC
Hello experts,
we have connected multiple ECC systems to GRC by creating connectors with respect to each system and
currently we are using,now due to some reasons customer requested to delete complete data from
one of the ECC system from GRC.
we are using only access control with all components
please suggest how to delete all relevant data
from GRC system
Thanks
GRC AdminHi,
You can use program GRAC_DELETE_ACCESS_RULES to achieve your requirement.
2075597 - How to delete specific system from SPRO
Regards,
Madhu. -
How to delete archive log files from ASM through Grid Control
Hi
Anybody suggest me how to delete archive log files from ASM through Grid Control.
ThanksIt is important to specify both, the oracle version and os version when posting, so confusions can be avoided.
In this particular case, since you are referring to asm and grid control you could be talking about either 10gR1, 10gR2 or 11gR1; but I strongly suggest you to avoid us to be guessing. In either case, you sould go to the maintenance tab of the target database and program a scheduled 'delete noprompt obsolete;' procedure. This will purge the information stored at the Flash recovery area, which I assume you have declared inside the ASM.
~ Madrid
http://hrivera99.blogspot.com/ -
Our daughter figured out on her own how to delete songs and apps from her IPAD2. Drives us crazy since we continually have to reload these files. Her parents would like to know
1. how she did it (delete files) and
2. how to prevent her from deleting files in the future.http://support.apple.com/kb/ht4213
Maybe you are looking for
-
Itunes Movie Rental Geographical Limitations and Offline Access
I live in Canada and will be travelling to Vegas next month. I'd like to be well prepared with some movie rentals through itunes on my macbook air. My concern is, would there be any geographical limitations in viewing movies in USA that have already
-
How can I get my 5524 to print 7x5 instead of 6x4 on 7x5 photo paper?
How can I get my photosmart 5524 to print proper size on 7x5 photo paper. It always comes out 6x4?
-
I have an HP Pro 3500 and my DVD drive only recognizes CDs and not DVDs I know the DVD is good since I can read it on my wife's laptop. It shows the DVD drive as drive F under Devices with removable storage but doesn't list it in the left column un
-
Assigning NULL in a select statement to a page item that doesn't exist? 2.2
Hi all, Should the following raise an exception or cause an error? It does not in APEX 2.2.0. This is in a PL/SQL region at the "After Header" render point. Using a value other that NULL causes an error. Thanks! BEGIN SELECT NULL INTO
-
Do you have to use the specific carrier for iphone 5?
I bought an unlocked iPhone 5 and then bought a separate T-Mobile nano sim but when I tried the sim it says "the sim is from a carrier that is not supported under the activation policy that is currently assigned by the activation server" I then check