如何使用指针传递值?

时间:2016-01-21 12:24:20

标签: c++

如果我有如下定义的功能,

public class DatabaseHandler extends SQLiteOpenHelper {

private static final String TAG = DatabaseHandler.class.getSimpleName();

//Database Version
private static final int DATABASE_VERSION = 1;

//Database Name
private static final String DATABASE_NAME = "aspinERP";

//Tables Name
private static final String CUSTOMER_TABLE = "customer_tb";
private static final String COLLECTION_TABLE = "collection_tb";
private static final String COLLECTION_LINE = "collectionline_tb";

//Common Column Name
private static final String CUSTOMER_CODE = "customer_code";
private static final String TRANSACTION_CODE = "transaction_code";
private static final String AMOUNT_DUE = "amount_due";


//Collection Table Columns Name
private static final String COLLECTION_CODE = "collection_code";
private static final String TIN = "tin";
private static final String OR_NO = "or_no";
private static final String DATE = "date";
private static final String AMOUNT_PAID = "amount_paid";
private static final String REMARKS = "remarks";
private static final String STATUS = "status";


//Collection_Line Columns Name
private static final String COLLECTION_LINE_ID = "collectionLine_id";
private static final String DOCUMENT_NO = "document_no";


//Customer Column Name
private static final String NAME = "customer_name";
private static final String AREA = "collector_name";


//Collection Create Table
private static final String CREATE_TABLE_COLLECTION = "CREATE TABLE "
        + COLLECTION_TABLE + "(" + COLLECTION_CODE + " TEXT PRIMARY KEY," +   
CUSTOMER_CODE
        + " TEXT," + TRANSACTION_CODE + " TEXT," + TIN + " TEXT," + OR_NO +  
" TEXT," + DATE
        + " TEXT," + AMOUNT_DUE + " TEXT," + AMOUNT_PAID + " TEXT," + 
REMARKS + " TEXT," + STATUS
        + " TEXT," + " FOREIGN KEY ("+CUSTOMER_CODE+") REFERENCES 
"+COLLECTION_TABLE+" ("+COLLECTION_CODE+"))";

//  + " FOREIGN KEY ("+CUSTOMER_CODE+") REFERENCES "+COLLECTION_TABLE+" 

  ("+COLLECTION_CODE+"))";

private static final String CREATE_TABLE_COLLECTION_LINE = "CREATE TABLE "
        + COLLECTION_LINE + "(" + COLLECTION_LINE_ID + " TEXT PRIMARY KEY," 
+ TRANSACTION_CODE
        + " TEXT," + DOCUMENT_NO + " TEXT," + AMOUNT_DUE + " TEXT" + ")";

private static final String CREATE_TABLE_CUSTOMER = "CREATE TABLE "
        + CUSTOMER_TABLE + "(" + CUSTOMER_CODE + " TEXT PRIMARY KEY," + NAME
        + " TEXT," + AREA + " TEXT" + ")";


public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {

    //Creating required tables
    db.execSQL(CREATE_TABLE_COLLECTION);
    db.execSQL(CREATE_TABLE_COLLECTION_LINE);
    db.execSQL(CREATE_TABLE_CUSTOMER);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    db.execSQL("DROP TABLE IF EXISTS " + COLLECTION_TABLE);
    db.execSQL("DROP TABLE IF EXISTS " + COLLECTION_LINE);
    db.execSQL("DROP TABLE IF EXISTS " + CUSTOMER_TABLE);

    //create new tables
    onCreate(db);

}

public void addCollection(String collection_code, String customer_code,   
String transaction_code,
                          String tin, String or_no, String date, String   
amount_due, String amount_paid,
                          String remarks, String status) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(COLLECTION_CODE, collection_code);
    values.put(CUSTOMER_CODE, customer_code);
    values.put(TRANSACTION_CODE, transaction_code);
    values.put(TIN, tin);
    values.put(OR_NO, or_no);
    values.put(DATE, date);
    values.put(AMOUNT_DUE, amount_due);
    values.put(AMOUNT_PAID, amount_paid);
    values.put(REMARKS, remarks);
    values.put(STATUS, status);

    //inserting row
    long id = db.insert(COLLECTION_TABLE, null, values);
    db.close();// closing database connection

    Log.d(TAG, "COLLECTION ADDED SUCCESSFULLY" + id);

 }

 public void addCustomer(String customer_code, String customer_name, String 

 area) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(CUSTOMER_CODE, customer_code);
    values.put(NAME, customer_name);
    values.put(AREA,area);

    long id = db.insert(CUSTOMER_TABLE, null, values);
    db.close();// closing database connection

    Log.d(TAG, "CUSTOMER ADDED SUCCESSFULLY" + id);
}

public void addCollectionLine(String collection_line_id, String 
transaction_code, String document_no,String amount_due){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(COLLECTION_LINE_ID, collection_line_id);
    values.put(TRANSACTION_CODE, transaction_code);
    values.put(DOCUMENT_NO, document_no);
    values.put(AMOUNT_DUE, amount_due);


    long id = db.insert(COLLECTION_LINE, null, values);
    db.close();

    Log.d(TAG, "COLLECTION LINE ADDED SUCCESSFULLY" + id);

}


public Customer_Model getcostumer(String customer_code){
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(CUSTOMER_TABLE, new String[]{ CUSTOMER_CODE, 
NAME,AREA }, CUSTOMER_CODE + "=?",
            new String[] { 
String.valueOf(customer_code)},null,null,null,null);

    if(cursor != null)
        cursor.moveToFirst();

    Customer_Model cm = new 
Customer_Model(cursor.getString(0),cursor.getString(1),cursor.getString(2));
    cursor.close();
    return cm;
}


public List<List_Collection_Model> getAllList(){
    List<List_Collection_Model> list_collection_models = new 
ArrayList<List_Collection_Model>();


    String selectQuery = "SELECT c." + COLLECTION_CODE + "," + " c." +  
CUSTOMER_CODE + "," + " c." + AMOUNT_DUE
            + "," + " a." + NAME + " FROM " + COLLECTION_TABLE + " c" + " 
LEFT JOIN " + CUSTOMER_TABLE + " a "
            + "ON" + " a." + CUSTOMER_CODE + " = " + "c." + CUSTOMER_CODE;


    SQLiteDatabase db = this.getWritableDatabase();
    Cursor c =  db.rawQuery(selectQuery, null);

    if(c.moveToFirst()){

        do{

            List_Collection_Model lc = new List_Collection_Model();

 lc.setCollection_code(c.getString(c.getColumnIndex(COLLECTION_CODE)));

 lc.setCustomer_code(c.getString(c.getColumnIndex(CUSTOMER_CODE)));
            lc.setCustomer_name(c.getString(c.getColumnIndex(NAME)));//              
 lc.setTransaction_no(c.getString(c.getColumnIndex(TRANSACTION_CODE)));
            lc.setAmount_due(c.getString(c.getColumnIndex(AMOUNT_DUE)));
            list_collection_models.add(lc);

            String log = lc.getCollection_code() + lc.getCustomer_code() + 
 lc.getCustomer_name() + lc.getAmount_due();
            Log.d("LOG", log);
        }while (c.moveToNext());

    }

    c.close();
    return list_collection_models;

}

}

我有一个指向void foo(MyObject o){ } 的指针,比如MyObject,如何使用指向对象的指针调用将对象作为参数传递的函数?

如何在不更改功能的正文/签名的情况下继续这样做。

1 个答案:

答案 0 :(得分:6)

只需

{{1}}

顺便说一句,这将创建一个副本。