Ejemplo n.º 1
0
        // Bare data

        public ContactBareDataDB GetContactBareDataByContactId(int contactId)
        {
            ContactBareDataDB bareData = new ContactBareDataDB();
            if (this.OpenConnection() == true)
            {
                string query = "SELECT * FROM contact_bare_data where contact_id = @contact_id";
                //Create Command
                SQLiteCommand cmd = new SQLiteCommand(query, connection);
                cmd.Parameters.AddWithValue("@contact_id", contactId);
                //Create a data reader and Execute the command
                SQLiteDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    int id = Int32.Parse(dataReader["id"].ToString());
                    string data = dataReader["bare_data"].ToString();

                    bareData.Id = id;
                    bareData.ContactId = contactId;
                    bareData.BareData = data;
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

            }
            return bareData;
        }
Ejemplo n.º 2
0
        // Insert bare data

        public int AddContactBareData(ContactBareDataDB bareData)
        {
            //open connection
            if (this.OpenConnection() == true)
            {
                SQLiteTransaction trans = connection.BeginTransaction();
                int res = -1;
                try
                {
                    SQLiteCommand comm = connection.CreateCommand();
                    comm.Transaction = trans;
                    comm.CommandText = "INSERT INTO contact_bare_data (contact_id, bare_data) VALUES(@contact_id, @bare_data)";
                    comm.Parameters.AddWithValue("@contact_id", bareData.ContactId);
                    comm.Parameters.AddWithValue("@bare_data", bareData.BareData);
                    comm.ExecuteNonQuery();


                    SQLiteCommand lastIdComm = connection.CreateCommand();
                    lastIdComm.CommandText = "SELECT last_insert_rowid()";
                    res = Int32.Parse(lastIdComm.ExecuteScalar().ToString());;

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                }
                //close connection
                this.CloseConnection();
                return res;
            }
            return -1;
        }
Ejemplo n.º 3
0
 public int AddContactBareData(ContactBareDataDB bareData)
 {
     DBManager db = new DBManager();
     return db.AddContactBareData(bareData);
 }