Monday, September 19, 2011

Import and Export MySQL Database

Export command:


By using mysqldump — A Database Backup Program.


mysqldump -u username -p -h localhost dbname > dbname_exported_file.sql


Where -u : username
      -p : password
      -h : host name


By using the above command line, we can export database into the specified file.


Import command:


If we need to import to exported sql file.


mysql -u username -p -h localhost dbname < dbname_exported_file.sql


It imports all the queries into the database.


For references, check the URL http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

Thursday, September 15, 2011

Mysql Error no: 150

ERROR 1025 (HY000): Can't create table '.\database\#sql-1295_318.frm' (errno: 150).
We will encounter this problem typically when the tables have been created with different Engines

E.g one is of the type INNODB and the other is of the type MyISAM.



Wednesday, September 14, 2011

Android Custom Component - Notify Number on icon


Custom Component using XML.

Basic approach to create your own View components:

·         Extending the View class for a completely custom component.
·         Parameterized constructor that takes the view inflation parameters (parameters defined in the XML). 
Create a custom component in xml (notifynumbercomp.xml) file with existing components available in android.

notifynumbercomp.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <RelativeLayout android:layout_width="32dip"
                        android:layout_height="wrap_content">
                        <ImageView android:src="@drawable/archive" android:id="@+id/NotifyImageView"
                                    android:layout_width="24dip" android:layout_height="24dip"
                                    android:paddingTop="3dip"></ImageView>
                        <TextView android:id="@+id/NotifyNumberTextView"
                                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                                    android:layout_alignParentRight="true" android:layout_alignParentTop="true"></TextView>
            </RelativeLayout>
</LinearLayout>


Create a class file, which extends View

NotifyNumberComponent.java

package com.cc.notify;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

public class NotifyNumberComponent extends LinearLayout {

            public NotifyNumberComponent(Context context, AttributeSet attrs) {
                        super(context, attrs);

                        LayoutInflater layoutInflater = (LayoutInflater) context
                                                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        View view = layoutInflater.inflate(R.layout.notifynumbercomp, this);
            }
}


Access the Custom component created in the main.xml file by loading view from Activity class.

NotifyNumber .java

package com.cc.notify;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class NotifyNumber extends Activity {
            /** Called when the activity is first created. */
            @Override
            public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.main);

                        int count = 3;

                        TextView notifyNumber = (TextView) findViewById(R.id.NotifyNumberTextView);
                        notifyNumber.setPadding(3, 1, 2, 0);
                        notifyNumber.setBackgroundResource(R.drawable.bg_num);
                        notifyNumber.getLayoutParams().height = 21;
                        notifyNumber.getLayoutParams().width = 19;
                        notifyNumber.setText("3");
                        notifyNumber.setTextColor(Color.WHITE);
                        notifyNumber.setVisibility(View.VISIBLE);

                        if (count == 0) {
                                    notifyNumber.setVisibility(View.GONE);
                        }
            }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <com.cc.notify.NotifyNumberComponent
                        android:layout_height="wrap_content" android:layout_width="fill_parent" />
</LinearLayout>

Output looks: