How to show Datepicker on Twitter Bootstrap

How to show Datepicker on Twitter Bootstrap

twitter bootstrap akhir-akhir ini mulai digemari untuk membangun sebuah website template, pada perkembangannya saat ini twitter bootstrap telah mencapai versi 3.0.3 dan anda bisa mendapatkannya di official sitenya getbootstrap.com. twitter bootstrap juga menyediakan datepicker dengan menggunakan jquery, dengan begitu akan lebih mudah mempercantik tampilan website kita dengan banyak fitur yang diberikan twitter bootstrap.
akan tetapi tahukah anda bahwa perbedaaan versi pada bootstrap 2 dan bootstrap versi 3 membuat datepicker tidak bekerja?. berikut cara menangani dan tutorial menambahkan datepicker pada bootstrap
untuk masalah kebutuhan, ketika ingin menggunakan datepicker bootstrap anda membutuhkan file berikut :
  1. jquery.js
  2. datepicker.js
  3. bootstrap.css
  4. datepicker.css
jika sudah ready, mari kita lihat kodenya ketika telah disisipkan file-file diatas :



  Datepicker author by @Andgaa 

 <!--this css for bootstrap 
 
 

Date picker for Bootstrap

-->
dengan kode html sederhana diatas anda sudah bisa menampilkan datepicker pada halaman template berbasis bootstrap anda, akan tetapi hal tersebut tidak berlaku pada versi bootstrap yang berbeda. jika anda menggunakan bootstrap 3 maka tutorial tersebut kemungkinan tidak akan berjalan pada bootstrap 2, karena terdapat perubahan class pada css dan javascript pada bootstrap. berikut merupakan cara yang dapat anda ikuti untuk menamplikan bootstrap dari bootstrap versi 2 ke bootstrap versi 3
perubahan bootstrap versi 2 ke versi 3
1. Css
buka file datepicker.css, temukan line 176 -177 seperti berikut :
.input-append.date .add-on i,
.input-prepend.date .add-on i {
lakukan berubahan pada line 176-177 dengan kode sebagai berikut :
.input-group.date .input-group-addon i,
.input-group.date .input-group-addon i {
2. Javascript
buka file datepicker-bootstrap.js, temukan line 34 seperti berikut :
this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
lakukan berubahan pada line 34 dengan kode sebagai berikut :
this.component = this.element.is('.date') ? this.element.find('.input-group-addon') : false;
3. Markup
setelah itu, untuk bootstrap versi 2 anda dapat memanggilnya dengan contoh seperti diberikut:
buat fungsi javascript untuk disisipkan di halaman html seperti contoh berikut

kemudian tampilkan datepicker dengan menyisipkan tag input yang diberi id=”datepicker”, dimana ID ini akan mereferensi kefungsi javascript yang sudah kita buat diatas, seperti berikut :

sedangkan, untuk bootstrap versi 3 anda dapat memanggilnya dengan contoh seperti diberikut:
buat fungsi javascript untuk disisipkan di halaman html seperti contoh berikut

kemudian tampilkan datepicker dengan menyisipkan tag div dengan class=”input-group date”, dimana class ini akan mereferensi kefungsi javascript yang sudah kita buat diatas, seperti berikut :
sebagai bahan percobaan, anda dapat mendownload cara menampilkan datapicker pada bootstrap disini

Referensi

How to Create Scheduled Events in MySQL

How to Create Scheduled Events in MySQL
This is the third and last article in a series about database automation with triggers and events. If you’ve not done so already, please read How to Create Triggers in MySQL which introduces many of the concepts discussed here.
An event is similar to a trigger. However, rather than running in response to a data change, events can be scheduled to run any number of times during a specific period. In effect, it’s a database-only cron job.
Events have been supported in MySQL since version 5.1. They are ideal for maintenance tasks such as data archiving or report generation which can be scheduled during off-peak times.

Our Database Plan

Our blog database has a problem. Old posts are marked as deleted rather than being removed from the `blog` table. Our table will grow indefinitely and become slower over time. We could purge the old posts but that would remove them forever. Therefore, we’ll move posts and their associated audit records to archive tables. The archive tables can grow without affecting the speed of the main web application and we can undelete old posts if necessary.
Two archive tables are required:
  • `blog_archive`: identical to the `blog` table except it does not require a deleted flag or an auto-incrementing ID.
  • `audit_archive`: identical to the `audit` table except the timestamp is not automatically generated and it does not require an auto-incrementing ID.
The following SQL creates both tables:

CREATE TABLE `blog_archive` (
 `id` mediumint(8) unsigned NOT NULL,
 `title` text,
 `content` text,
 PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Blog posts archive';
-- 
CREATE TABLE `audit_archive` (
 `id` mediumint(8) unsigned NOT NULL,
 `blog_id` mediumint(8) unsigned NOT NULL,
 `changetype` enum('NEW','EDIT','DELETE') NOT NULL,
 `changetime` timestamp NOT NULL,
 PRIMARY KEY (`id`),
 KEY `ix_blog_id` (`blog_id`),
 KEY `ix_changetype` (`changetype`),
 KEY `ix_changetime` (`changetime`),
 CONSTRAINT `FK_audit_blog_archive_id` FOREIGN KEY (`blog_id`) REFERENCES `blog_archive` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Starting MySQL’s Event Scheduler

MySQL events are executed by a special event scheduler thread. It’s disabled by default so use the following MySQL command can determine whether it’s running:

SHOW PROCESSLIST;
If the scheduler is running, at least two rows will be shown and one will have its user field set to “event_scheduler”. If only one row is returned, the scheduler is disabled and events will not run.
You can ensure the scheduler starts when MySQL is launched with the command-line option --event-scheduler=ON or setting event_scheduler=ON in your MySQL configuration file (my.cnf or my.ini on Windows).
Alternatively, you can start the scheduler from the MySQL command line:

SET GLOBAL event_scheduler = ON;

Creating an Event

We require a scheduled event which:
  • Copies posts from `blog` to `blog_archive` when the deleted flag is set to 1.
  • Copies the associated audit entries for those posts from `audit` to `audit_archive`.
  • Physically deletes archived posts from the `blog` table. Referential integrity has been defined with a foreign key so all associated audit entries for those posts will also be removed.
Assuming you have MySQL rights to create events, the basic syntax is:

CREATE EVENT `event_name` 
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE] 
[ENABLE | DISABLE | DISABLE ON SLAVE]
DO BEGIN
 -- event body
END;
The schedule can be assigned various settings, e.g.
  • Run once on a specific date/time:
    AT ‘YYYY-MM-DD HH:MM.SS’
    e.g. AT ’2011-06-01 02:00.00′
  • Run once after a specific period has elapsed:
    AT CURRENT_TIMESTAMP + INTERVAL n [HOUR|MONTH|WEEK|DAY|MINUTE]
    e.g. AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
  • Run at specific intervals forever:
    EVERY n [HOUR|MONTH|WEEK|DAY|MINUTE]
    e.g. EVERY 1 DAY
  • Run at specific intervals during a specific period:
    EVERY n [HOUR|MONTH|WEEK|DAY|MINUTE] STARTS date ENDS date
    e.g. EVERY 1 DAY STARTS CURRENT_TIMESTAMP + INTERVAL 1 WEEK ENDS ’2012-01-01 00:00.00′
An event is normally dropped once its schedule has expired (ON COMPLETION NOT PRESERVE). Set ON COMPLETION PRESERVE to prevent that behavior. The MySQL CREATE EVENT Syntax documentation provides further details.
We can now define our event (remembering to set the DELIMITER first). We’ll set it to run every week starting on a Sunday morning:

DELIMITER $$

CREATE 
 EVENT `archive_blogs` 
 ON SCHEDULE EVERY 1 WEEK STARTS '2011-07-24 03:00:00' 
 DO BEGIN
 
  -- copy deleted posts
  INSERT INTO blog_archive (id, title, content) 
  SELECT id, title, content
  FROM blog
  WHERE deleted = 1;
     
  -- copy associated audit records
  INSERT INTO audit_archive (id, blog_id, changetype, changetime) 
  SELECT audit.id, audit.blog_id, audit.changetype, audit.changetime 
  FROM audit
  JOIN blog ON audit.blog_id = blog.id
  WHERE blog.deleted = 1;
  
  -- remove deleted blogs and audit entries
  DELETE FROM blog WHERE deleted = 1;
     
 END */$$

DELIMITER ;
This is a simple example but you could add more functionality, e.g. only move posts which were deleted at least 1 month ago and purge all archieved posts over 1 year old. I hope you’ve enjoyed this series and are considering database triggers and events in your next project.


Reference : http://www.sitepoint.com/how-to-create-mysql-events/

Allowing SQL Server Connection From Network

Allowing SQL Server Connection From Network
Upon database modeling with the ORM feature, you always need to connect to the server. However, you may encounter problem in connecting to the SQL server, which is great obstruction to your modeling. In this article, we will provide ways to help you to check whether your configurations for connecting to SQL Server are correct.
There are three significant aspects that uses may neglect, leading the failure of the connection to the SQL Server.

Server Settings

Enable TCP/IP

  1. Open your SQL Server Configuration Manager.
    open sql config manager
  2. Expand SQL Server Network Configuration and select Protocols for SQLEXPRESS.
    sql network config express
  3. Take a look at TCP/IP, which requires to be Enabled. If yours is Disabled, right-click on it and select Enable in the popup menu.
    enable tcp ip
  4. Also, you may take a look at the Port setting of your server. Right-click on TCP/IP and select Properties in the popup menu.
    right click tcp ip properties
  5. Click the IP Address tab in the TCP/IP Properties dialog box.
    click ip address tab
  6. Under IPAll section, you can see the TCP Port (default: 1433) and you can edit the port of your server.
    tcp port

Correct Hostname and Port

Back to your VP application, have a check in your database configuration and see if you have entered the Hostname and Port correctly.
  1. Select Tools > Object-Relational Mapping (ORM) > Database Configuration in the VP application.
    tool orm db config
  2. Select the Language, server and the driver in the Database Configuration dialog box.
    select lang server driver
  3. Enter Hostname, which must be either the IP address of your computer or your computer name.
    db config hostname
  4. Enter the port of your SQL Server. It's 1433 by default, but if you have edited the port for your SQL Server or running on other named instance, you need to enter the corresponding port.
    db config port

Allow Remote Connection

Your need to make sure that remote connection to your SQL Server is enabled.
  1. Startup your SQL Server.
    start sql server
  2. Right-click on the server and select Properties in the popup menu.
    right click sql server properties
  3. In the Server Properties dialog box, select Connections.
    select connection
  4. Check the checkbox of Allow remote connections to this server.
    check allow remote connection

Diagnosis of Connection in Command Line

You can diagnose whether your SQL Server is in-use by the command line. For Windows Vista, Telnet is not installed by default, you need to install it before running the telnet command.

Install Telnet Client in Windows Vista

  1. Open Control Panel from the Start Menu.
    control panel
  2. Select Programs in the Control Panel.
    select programs
  3. Under Programs and Features, select Turn Windows features on or off.
    select turn on off win features
  4. Scroll down to find the option Telnet Client, check this option and press OK.
    select telnet client

Run Telnet Command

  1. Shutdown your SQL Server first and launch the command prompt.
  2. Enter telnet %host% %port% in the command prompt, where %host% and %port% are the host and port of your SQL Server.
    enter telnet msg in command
  3. Press Enter to see if it can call the SQL Server. If telnet can communicate with the host and port you specified, it will show a blank dialog box. This means your SQL Server is able to be connected.
    telnet succeed connect to sql
    If it fails to connect to your SQL Server, there will be message of the failure.
    telnet cannot connect to sql

Authentication Method

Make sure that you are using the appropriate authentication method in connecting to your SQL Server.
  1. Startup your SQL Server.
    start sql server
  2. Right-click on the server and select Properties in the popup menu.
    right click sql server properties
  3. In the Server Properties dialog box, select Security.
    select security
  4. Normally, the Server Authentication is set to SQL Server and Windows Authentication Method.
    select sql and win auth
  5. If you are using the Windows Authentication Method, you will need another connection URL in order to connect to the SQL Server.
    • Java (SQL Server 2005 Microsoft Driver)
      jdbc:sqlserver://localhost;databaseName=AdventureWorks;integratedSecurity=true;
    • Java (jDTS)
      jdbc:jtds:://[:][/];domain=XXX
      where = sqlserver
      ** Domain Server is required. If no domain server is available, please try domain=workgroup
    • .NET:
      Server=%HOST%,%PORT%;Database=%DATABASE%;User ID=%USER_ID%;Password=%PASSWD%;Trusted_Connection=Yes;Domain=%WINDOW_DOMAIN%
  6. Get back to the VP application and enter the URL in the Connection String section in the Database Configuration dialog box.
    enter url in connection string

Adapter File

While you are using can non-compatible adapter file, you will not be able to connect to the server.
The simplest way to get the compatible adapter file is let our application download it for you:
  1. Select Tools > Object-Relational Mapping (ORM) > Database Configuration.
    tool orm db config
  2. After you have chosen the language, server and driver, click the Download and Update button beside the Adapter file field.
    dl adapter file
  3. VP will download the adapter file for you.
    adapter file downloaded
If your still fail to connect to SQL server with all the above steps of checking, please contact support-team@visual-paradigm.com for technical suppot.

Connection To Microsoft SQL Server Database From Python

Connection To Microsoft SQL Server Database From Python

Free tools are great, but the world ain't all sunshine and rainbows. Sometimes, we may need to connect to a Microsoft SQL Server database from one of our Python applications running under Linux. Fortunately, there are ways to achieve this.
I am assuming we got this:
  • • A Microsoft SQL Server installation running under Windows. I tested this using Microsoft SQL Server 2008 R2 Express, but hopefully this will work with other versions as well.
  • Ubuntu Linux. I am using 12.04 LTS.
Without further ado, here are the steps you should follow to get this working.

1. SQL Server setup

Your SQL Server installation must be setup to allow external connections. If the DB is not administered by you this might not be a problem, but in case you do have administrator level access and need to do it yourself, read here.
Now you must have setup a port in which SQL Server is listening. Remember it.
Make sure you are not blocked by Windows firewall or such when you attempt to connect to the Windows computer. Attempting a telnet will help us check if there are connection problems. For example, try running telnet from Ubuntu and check the connection doesn't fail.
Regarding authentication, I have only tried this with the sa login enabled (ie. not using Windows Authentication). You may read on how to do that here.

2. Install required packages under Ubuntu

These are the things we are going to need:
  • FreeTDS is is a set of libraries that allows programs to natively talk to Microsoft SQL Server databases. It's what we usually call a driver.
  • UnixODBC acts as a driver manager and is the implementation of the ODBC API.
  • pyodbc is a Python 2.x and 3.x module that allows you to use ODBC to connect to almost any database.
From a terminal, run:
sudo apt-get install unixodbc unixodbc-dev freetds-dev tdsodbc
From the Virtualenv of our Python application (if you are not using one, you should!) run pip install pyodbc.

3. Setup server in FreeTDS's settings

Edit the file /etc/freetds/freetds.conf and replace placeholders appropriately. Note that we are calling our server sqlserver.
[sqlserver]
    host = 
    port = 
    tds version = 7.0
After this you can test the connection with this command:
tsql -S sqlserver -U  -P 
note : tsql not build in freetds, you can add with apt-get install freetds-bin

Then run some SQL Server command to make sure everything works fine. For example you may run a DB query like this:
select * from .dbo.
go
If it worked, it will print the results of the query. Quit with Ctrl+D.

4. Setup unixODBC to use FreeTSD & add a data source

First, run odbcinst -j to know where our configuration files are located. We will need to edit two files: the "drivers" and "system data source". I assume they are /etc/odbcinst.ini and /etc/odbc.ini respectively, but the output of the command will tell you this.

Edit /etc/odbcinst.ini like this:
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
# Some installations may differ in the paths
#Driver = /usr/lib/odbc/libtdsodbc.so
#Setup = /usr/lib/odbc/libtdsS.so
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
If the paths for Driver and Setup do not work in your installation, you can find where these files are located by running find / -name "libtds*".
Edit /etc/odbc.ini like this, to add a data source named sqlserverdatasource:
[sqlserverdatasource]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = sqlserver
Database = 
Now you may test the connection to out data source works by running isql -v sqlserverdatasource .

5. Connect to our data source from a Python application

If everything is fine, with the help of pyodbc it should be really easy! You may try the following snippet:
import pyodbc
dsn = 'sqlserverdatasource'
user = ''
password = ''
database = ''
con_string = 'DSN=%s;UID=%s;PWD=%s;DATABASE=%s;' % (dsn, user, password, database)
cnxn = pyodbc.connect(con_string)


That should be it :-)

ref : http://www.tryolabs.com/Blog/2012/06/25/connecting-sql-server-database-python-under-ubuntu/