2011-10-04 15 views
6

मुझे स्वतंत्र रूप से तीन तालिकाओं को सम्मिलित करना होगा .. लेकिन यदि पहली तालिका सफलतापूर्वक डाली जाती है, तो डेटा डालने के लिए केवल 2 तालिका की आवश्यकता होती है।एंड्रॉइड एसक्यूएलएट लेनदेन रोलबैक सुविधा?

मैं वर्तमान में इस तरह किया: 2 तालिका सम्मिलित करते हुए किसी भी त्रुटि तब होती है, तो यह 1 तालिका के अंतिम डाला एक, वैसे ही 3 टेबल भी रोलबैक करने की जरूरत है

DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(RetailerOrderActivity.this); 
dbAdapter.openDataBase(); 
    for (Map.Entry<String, MyProduct> entry : myProductMap.entrySet()) { 
        String key = entry.getKey(); 
        MyProduct myProduct = entry.getValue(); 

        ContentValues initialValue = new ContentValues(); 
        initialValue.put("BusinessUnit",strBusinessUnit); 
        initialValue.put("ExecutiveCode",strExecutive); 

        if(salesType.equalsIgnoreCase("I")){ 
         initialValue.put("InvoiceNo",transactionControl.getNextInvoiceNo()); 
         initialValue.put("SalesCategory",transactionControl.getInvoicePrefix()); 

        }else if(salesType.equalsIgnoreCase("O")){ 
         initialValue.put("InvoiceNo",transactionControl.getNextOrderNo()); 
         initialValue.put("SalesCategory",transactionControl.getOrderPrefix()); 
        } 
        initialValue.put("ProductCode",key); 
        initialValue.put("LineNumber",i); 
        initialValue.put("Qty",myProduct.getQty()); 
        initialValue.put("UnitPrice",myProduct.getPrice()); 
        initialValue.put("DiscountValue",myProduct.getDisValue()); 
        initialValue.put("DiscountQty",myProduct.getDisQty()); 


        long nl = dbAdapter.insertRecordsInDB("WMInvoiceLine", null, initialValue); 

        //update WMStockRecord table 
        if(nl != -1){ 

         if((salesType.equalsIgnoreCase("I") && orderStockValidation.equals("1")) || (salesType.equalsIgnoreCase("O") && orderStockValidation.equals("1"))){ 
          ContentValues stockValue = new ContentValues(); 
          if(myProduct.getAvailableQuantity() < myProduct.getQty()){ 
           stockValue.put("Stock",0.00); 
          }else{ 
           double tmp = myProduct.getAvailableQuantity() - myProduct.getQty(); 
           stockValue.put("Stock",tmp); 
          } 
          stockValue.put("LastUpdatedOn",strDate); 
          stockValue.put("LastUpdatedBy",strExecutive); 
          stockValue.put("ActiveStatus","1"); 

          String whereCon = "BusinessUnit = '"+ strBusinessUnit +"' WarehouseCode = '"+defaultSalesWarehouse + "' LocationCode = '" + defaultSalesLocation + "' ProductCode = '" + key + "'"; 
          long stock = dbAdapter.updateRecordsInDB("WMStockRecord", stockValue, whereCon, null); 
         } 

         //TO-DO WMInvoicekit 
        } 

        i++; 
        insertStatus = true; 
        lineStatus = true; 
       } 

लेकिन यहाँ नहीं लेन-देन नहीं है उपलब्ध। हम लेनदेन सुविधा कैसे कार्यान्वित कर सकते हैं? मैं DBAdapter

उत्तर

4

आपको लेनदेन सेट करना होगा और यदि आप सफल होते हैं तो आपको वह लेनदेन करना होगा, आपको उस लेनदेन को रद्द करना होगा।

अधिक जानकारी के लिए आप इस जवाब का उल्लेख कर सकते

Transaction in sqlite

संबंधित मुद्दे