Author Archives: mCube

About mCube

Software Developer Bangalore

Row Count for all Tables in a Database

Standard

Execute the below script if you got the result then fine otherwise go with step 2
=============================================================
DECLARE @TableRowCounts TABLE ([TableName] VARCHAR(128), [RowCount] INT) ;
INSERT INTO @TableRowCounts ([TableName], [RowCount])
EXEC sp_MSforeachtable ‘SELECT ”?” [TableName], COUNT(*) [RowCount] FROM ? ‘ ;
SELECT [TableName], [RowCount]
FROM @TableRowCounts where [RowCount] > 0
ORDER BY [TableName]
GO
==============================================================
Step 2

Run this stored procedure in SQL server mostly this SP already available in the SQL server.

Stored Procedure -1

create proc sys.sp_MSforeachtable
@command1 nvarchar(2000),  @replacechar nchar(1) = N’?’,  @command2 nvarchar(2000) = null, @command3 nvarchar(2000) = null,  @whereand nvarchar(2000) = null, @precommand nvarchar(2000) = null,  @postcommand nvarchar(2000) = null
as
/* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its own result set */
/* @precommand and @postcommand may be used to force a single result set via a temp table. */

/* Preprocessor won’t replace within quotes so have to use str(). */
declare @mscat nvarchar(12)
select @mscat = ltrim(str(convert(int, 0x0002)))

if (@precommand is not null)
exec(@precommand)

/* Create the select */
exec(N’declare hCForEachTable cursor global for select ”[” + REPLACE(schema_name(syso.schema_id), N”]”, N”]]”) + ”]” + ”.” + ”[” + REPLACE(object_name(o.id), N”]”, N”]]”) + ”]” from dbo.sysobjects o join sys.all_objects syso on o.id = syso.object_id ‘
+ N’ where OBJECTPROPERTY(o.id, N”IsUserTable”) = 1 ‘ + N’ and o.category & ‘ + @mscat + N’ = 0 ‘
+ @whereand)
declare @retval int
select @retval = @@error
if (@retval = 0)
exec @retval = sys.sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0

if (@retval = 0 and @postcommand is not null)
exec(@postcommand)

return @retval

Stored Procedure-2

/*
* This is the worker proc for all of the “for each” type procs.  Its function is to read the
* next replacement name from the cursor (which returns only a single name), plug it into the
* replacement locations for the commands, and execute them.  It assumes the cursor “hCForEach***”
* has already been opened by its caller.
* worker_type is a parameter that indicates whether we call this for a database (1) or for a table (0)
*/
create proc sys.sp_MSforeach_worker
@command1 nvarchar(2000),  @replacechar nchar(1) = N’?’,  @command2 nvarchar(2000) = null,  @command3 nvarchar(2000) = null,  @worker_type int =1
as

create table #qtemp ( /* Temp command storage */
qnum int NOT NULL,
qchar nvarchar(2000) COLLATE database_default NULL
)

set nocount on
declare @name nvarchar(517), @namelen int, @q1 nvarchar(2000), @q2 nvarchar(2000)
declare @q3 nvarchar(2000), @q4 nvarchar(2000), @q5 nvarchar(2000)
declare @q6 nvarchar(2000), @q7 nvarchar(2000), @q8 nvarchar(2000), @q9 nvarchar(2000), @q10 nvarchar(2000)
declare @cmd nvarchar(2000), @replacecharindex int, @useq tinyint, @usecmd tinyint, @nextcmd nvarchar(2000)
declare @namesave nvarchar(517), @nametmp nvarchar(517), @nametmp2 nvarchar(258)

declare @local_cursor cursor
if @worker_type=1
set @local_cursor = hCForEachDatabase
else
set @local_cursor = hCForEachTable

open @local_cursor
fetch @local_cursor into @name

/* Loop for each database */
while (@@fetch_status >= 0) begin
/* Initialize. */

/* save the original dbname */
select @namesave = @name
select @useq = 1, @usecmd = 1, @cmd = @command1, @namelen = datalength(@name)
while (@cmd is not null) begin /* Generate @q* for exec() */
/*
* Parse each @commandX into a single executable batch.
* Because the expanded form of a @commandX may be > OSQL_MAXCOLLEN_SET, we’ll need to allow overflow.
* We also may append @commandX’s (signified by ‘++’ as first letters of next @command).
*/
select @replacecharindex = charindex(@replacechar, @cmd)
while (@replacecharindex 0) begin

/* 7.0, if name contains ‘ character, and the name has been single quoted in command, double all of them in dbname */
/* if the name has not been single quoted in command, do not doulbe them */
/* if name contains ] character, and the name has been [] quoted in command, double all of ] in dbname */
select @name = @namesave
select @namelen = datalength(@name)
declare @tempindex int
if (substring(@cmd, @replacecharindex – 1, 1) = N””) begin
/* if ? is inside of ”, we need to double all the ‘ in name */
select @name = REPLACE(@name, N””, N”””)
end else if (substring(@cmd, @replacecharindex – 1, 1) = N'[‘) begin
/* if ? is inside of [], we need to double all the ] in name */
select @name = REPLACE(@name, N’]’, N’]]’)
end else if ((@name LIKE N’%].%]’) and (substring(@name, 1, 1) = N'[‘)) begin
/* ? is NOT inside of [] nor ”, and the name is in [owner].[name] format, handle it */
/* !!! work around, when using LIKE to find string pattern, can’t use ‘[‘, since LIKE operator is treating ‘[‘ as a wide char */
select @tempindex = charindex(N’].[‘, @name)
select @nametmp  = substring(@name, 2, @tempindex-2 )
select @nametmp2 = substring(@name, @tempindex+3, len(@name)-@tempindex-3 )
select @nametmp  = REPLACE(@nametmp, N’]’, N’]]’)
select @nametmp2 = REPLACE(@nametmp2, N’]’, N’]]’)
select @name = N'[‘ + @nametmp + N’].[‘ + @nametmp2 + ‘]’
end else if ((@name LIKE N’%]’) and (substring(@name, 1, 1) = N'[‘)) begin
/* ? is NOT inside of [] nor ”, and the name is in [name] format, handle it */
/* j.i.c., since we should not fall into this case */
/* !!! work around, when using LIKE to find string pattern, can’t use ‘[‘, since LIKE operator is treating ‘[‘ as a wide char */
select @nametmp = substring(@name, 2, len(@name)-2 )
select @nametmp = REPLACE(@nametmp, N’]’, N’]]’)
select @name = N'[‘ + @nametmp + N’]’
end
/* Get the new length */
select @namelen = datalength(@name)

/* start normal process */
if (datalength(@cmd) + @namelen – 1 > 2000) begin
/* Overflow; put preceding stuff into the temp table */
if (@useq > 9) begin
close @local_cursor
if @worker_type=1
deallocate hCForEachDatabase
else
deallocate hCForEachTable

RAISERROR(55555, 16, 1); — N’sp_MSforeach_worker assert failed:  command too long’
return 1
end
if (@replacecharindex < @namelen) begin
/* If this happened close to beginning, make sure expansion has enough room. */
/* In this case no trailing space can occur as the row ends with @name. */
select @nextcmd = substring(@cmd, 1, @replacecharindex)
select @cmd = substring(@cmd, @replacecharindex + 1, 2000)
select @nextcmd = stuff(@nextcmd, @replacecharindex, 1, @name)
select @replacecharindex = charindex(@replacechar, @cmd)
insert #qtemp values (@useq, @nextcmd)
select @useq = @useq + 1
continue
end
/* Move the string down and stuff() in-place. */
/* Because varchar columns trim trailing spaces, we may need to prepend one to the following string. */
/* In this case, the char to be replaced is moved over by one. */
insert #qtemp values (@useq, substring(@cmd, 1, @replacecharindex – 1))
if (substring(@cmd, @replacecharindex – 1, 1) = N' ') begin
select @cmd = N' ' + substring(@cmd, @replacecharindex, 2000)
select @replacecharindex = 2
end else begin
select @cmd = substring(@cmd, @replacecharindex, 2000)
select @replacecharindex = 1
end
select @useq = @useq + 1
end
select @cmd = stuff(@cmd, @replacecharindex, 1, @name)
select @replacecharindex = charindex(@replacechar, @cmd)
end

/* Done replacing for current @cmd.  Get the next one and see if it's to be appended. */
select @usecmd = @usecmd + 1
select @nextcmd = case (@usecmd) when 2 then @command2 when 3 then @command3 else null end
if (@nextcmd is not null and substring(@nextcmd, 1, 2) = N'++') begin
insert #qtemp values (@useq, @cmd)
select @cmd = substring(@nextcmd, 3, 2000), @useq = @useq + 1
continue
end

/* Now exec() the generated @q*, and see if we had more commands to exec().  Continue even if errors. */
/* Null them first as the no-result-set case won't. */
select @q1 = null, @q2 = null, @q3 = null, @q4 = null, @q5 = null, @q6 = null, @q7 = null, @q8 = null, @q9 = null, @q10 = null
select @q1 = qchar from #qtemp where qnum = 1
select @q2 = qchar from #qtemp where qnum = 2
select @q3 = qchar from #qtemp where qnum = 3
select @q4 = qchar from #qtemp where qnum = 4
select @q5 = qchar from #qtemp where qnum = 5
select @q6 = qchar from #qtemp where qnum = 6
select @q7 = qchar from #qtemp where qnum = 7
select @q8 = qchar from #qtemp where qnum = 8
select @q9 = qchar from #qtemp where qnum = 9
select @q10 = qchar from #qtemp where qnum = 10
truncate table #qtemp
exec (@q1 + @q2 + @q3 + @q4 + @q5 + @q6 + @q7 + @q8 + @q9 + @q10 + @cmd)
select @cmd = @nextcmd, @useq = 1
end /* while @cmd is not null, generating @q* for exec() */

/* All commands done for this name.  Go to next one. */
fetch @local_cursor into @name
end /* while FETCH_SUCCESS */
close @local_cursor
if @worker_type=1
deallocate hCForEachDatabase
else
deallocate hCForEachTable

return 0

Capture

Advertisements

odoo(OpenERP V7.0) installation on ubuntu 12.04 Desktop

Standard

 

First Of all open your terminal ( ALT + CTR + T) and copy paste given bellow command in order

 

Step 1. Build your server first

 

  •     sudo apt-get install openssh-server denyhosts

Now make sure your server has all the latest versions & patches by doing an update:

  •       sudo apt-get update
  •       sudo apt-get dist-upgrade

Now we’re ready to start the OpenERP install.

Step 2. Create the OpenERP user that will own and run the application

 

  • sudo adduser –system –home=/opt/openerp –group openerp                                                                                                                    (Here you can change your folder name  instead of OPT -> Ur folder name )

 

  • sudo su – openerp -s /bin/bash
  • exit.

Step 3. Install and configure the database server, PostgreSQL

 

  • sudo apt-get install postgresql

(Then configure the OpenERP user on postgres: First change to the postgres user so we have the necessary privileges to configure the database. )

  • sudo su – postgres

(Now create a new database user. This is so OpenERP has access rights to connect to PostgreSQL and to create and drop databases. Remember what your choice of password is here; you will need it later on:)

 

  • createuser –createdb –username postgres –no-createrole –no-superuser –pwprompt openerp

Enter password for new role:      ********         ( recommended password : openepgpwd or as ur wish )

Enter it again:      ********

 

Finally exit from the postgres user account:

  •    exit

 

Step 4. Install the necessary Python libraries for the server

 

  • sudo apt-get install python-dateutil python-docutils python-feedparser python-gdata \ python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid \ python-psycopg2 python-psutil python-pybabel python-pychart python-pydot python-pyparsing \ python-reportlab python-simplejson python-tz python-unittest2 python-vatnumber python-vobject \ python-webdav python-werkzeug python-xlwt python-yaml python-zsi

( Please install one by one python package like –>>> sudo apt-get install python-dateutil-docutils  )

 

Step 5. Install the OpenERP server

Now install the code where we need it: cd to the /opt/openerp/ directory and extract the tarball there.

  • cd /opt/openerp

 

  • sudo tar xvf ~/openerp-7.0-latest.tar.gz    ( if any error comes type below command)
    • sudo tar zxvf ~/openerp-7.0-latest.tar.gz    

 

  • sudo chown -R openerp: *
  • sudo cp -a openerp-7.0 server

Step 6. Configuring the OpenERP application

(The default configuration file for the server (in /opt/openerp/server/install/) is actually very minimal and will, with only one small change work fine so we’ll simply copy that file to where we need it and change it’s ownership and permissions:)

  • sudo cp /opt/openerp/server/install/openerp-server.conf /etc/
  • sudo chown openerp: /etc/openerp-server.conf
  • sudo chmod 640 /etc/openerp-server.conf

 

  • sudo nano /etc/openerp-server.conf

(we might as well add to the configuration file now, is to tell OpenERP where to write its log file. To complement my suggested location below add the following line to the openerp-server.conf file: logfile = /var/log/openerp/openerp-server.log

and remove the semicolon in db_password only

 

Once the configuration file is edited and saved, you can start the server just to check if it actually runs.

 

  • sudo su – openerp -s /bin/bash
  • /opt/openerp/server/openerp-server

** if any comes here trace the error like package not installed  whatever just install those package like

sudo apt-get install ……Package name …….. (i faced these error while installing python package not installed

( sudo apt-get install python-werkzeug   like this u can resolve the error)

or type this command

 

  • sudo apt-get install python-pip
  • sudo pip install gdata –upgrade

if everything is ok then once again start the service

  • sudo su – openerp -s /bin/bash
  • /opt/openerp/server/openerp-server

simply enter CTL+C to stop the server and then exit to leave the openerp user account and go back to your own shell.

 

Step 7. Installing the boot script  ( to start the server automatically )

 

There is a script you can use in /opt/openerp/server/install/openerp-server.init   (  you need to either copy it or paste the contents of this script (openerp-server.init )to a file in /etc/init.d/

Or copy and paste below script and save as file .init  put into  —>  /etc/init.d/

#!/bin/sh

### BEGIN INIT INFO
# Provides:             openerp-server
# Required-Start:       $remote_fs $syslog
# Required-Stop:        $remote_fs $syslog
# Should-Start:         $network
# Should-Stop:          $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Enterprise Resource Management software
# Description:          Open ERP is a complete ERP and CRM software.
### END INIT INFO

PATH=/bin:/sbin:/usr/bin
DAEMON=/opt/openerp/server/openerp-server
NAME=openerp-server
DESC=openerp-server

# Specify the user name (Default: openerp).
USER=openerp

# Specify an alternate config file (Default: /etc/openerp-server.conf).
CONFIGFILE="/etc/openerp-server.conf"

# pidfile
PIDFILE=/var/run/$NAME.pid

# Additional options that are passed to the Daemon.
DAEMON_OPTS="-c $CONFIGFILE"

[ -x $DAEMON ] || exit 0
[ -f $CONFIGFILE ] || exit 0

checkpid() {
    [ -f $PIDFILE ] || return 1
    pid=`cat $PIDFILE`
    [ -d /proc/$pid ] && return 0
    return 1
}

case "${1}" in
        start)
                echo -n "Starting ${DESC}: "

                start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
                        --chuid ${USER} --background --make-pidfile \
                        --exec ${DAEMON} -- ${DAEMON_OPTS}

                echo "${NAME}."
                ;;

        stop)
                echo -n "Stopping ${DESC}: "

                start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
                        --oknodo

                echo "${NAME}."
                ;;

        restart|force-reload)
                echo -n "Restarting ${DESC}: "

                start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
                        --oknodo
      
                sleep 1

                start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
                        --chuid ${USER} --background --make-pidfile \
                        --exec ${DAEMON} -- ${DAEMON_OPTS}

                echo "${NAME}."
                ;;

        *)
                N=/etc/init.d/${NAME}
                echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2
                exit 1
                ;;
esac

exit 0

 

Once it is in the right place you will need to make it executable and owned by root:

  • sudo chmod 755 /etc/init.d/openerp-server.init
  • sudo chown root: /etc/init.d/openerp-server.init

 

In the configuration file there’s an entry for the server’s log file. We need to create that directory first so that the server has somewhere to log to and also we must make it writeable by the openerp user:

  • sudo mkdir /var/log/openerp
  • sudo chown openerp:root /var/log/openerp

Step 8. Testing the server

 

  •    sudo /etc/init.d/openerp-server.init start

it will look like this

 

OpenERP 7 Database Management Screen

 

 

 

 

 

 

Paging in JSP without DisplayTag Library.

Standard

<%–
Document : index
Created on : Mar 28, 2013, 2:07:24 PM
Author : MOZIB
–%>

<%@page contentType=”text/html” pageEncoding=”UTF-8″%>
<%@taglib prefix=”c” uri= “http://java.sun.com/jsp/jstl/core”%&gt;
<%@taglib prefix=”sql” uri= “http://java.sun.com/jsp/jstl/sql&#8221; %>
<sql:setDataSource driver=”com.mysql.jdbc.Driver”></sql:setDataSource>
<sql:setDataSource driver=”com.mysql.jdbc.Driver” url=”jdbc:mysql://localhost:3306/testdata” user=”root” password=”password”></sql:setDataSource>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>Dynamic page</title>
</head>

<body>

<table border=”1″ align=”center”>
<br>
<form>
<%– <h5>Select the limit to display the pages</h5>
<select name=”se” onchange=”form.submit()”>

<option value=”select” >
select
</option>
<option value=”5″ > 5 </option><option value=”10″ >10</option>

<option value=”15″ >
15
</option>
<option value=”${20}” >
20
</option>

</select>

</form>
<c:set var=”limit” value=”${param.se}”></c:set> –%>
<h1><center><font color=”green”>Order Booking Transanction </font></center></h1>

<sql:query var=”max1″ sql=”select count(*) as m from orderbooking_trans”></sql:query>

<c:forEach var=”r” items=”${max1.rows}”>
<c:set var=”temp” value=”${r.m}”></c:set>

</c:forEach>

<c:set var=”z” value=”${param.id}”></c:set>
<c:set var=”t” value=”${0+z}”></c:set>
<c:set var=”s” value=”${t+10}”></c:set>
<c:set var=”f” value=”${t-10}”></c:set>
<c:if test=”${s gt t}”>
<sql:query var=”d” sql=”select * from orderbooking_trans limit ${t},10″></sql:query>
<c:forEach var=”x” items=”${d.rows}”>
<tr><td>${x.Order_Id}</td><td>${x.Prospect_Id}</td><td>${x.Emp_Id}</td>
<td>${x.Order_date}</td><td>${x.Subvention}</td><td>${x. Margin}</td>
<td>${x.Spl_Offers}</td><td>${x.Dsa_Payout}</td><td>${x.FleetAmt}</td><td>${x.TotalOutFlow}</td>
<td>${x.TotalInFlow}</td><td>${x.TotalCosttoDlrship}</td><td>${x.CustType}</td>
<td>${x.ModeOfPurchase}</td><td>${x.FSource_Id}</td>
<td>${x.Paper_Fleet}</td></tr>
<c:if var=”max” test=”${x eq null}”>
</c:if>
</c:forEach>
</c:if>
<c:if test=”${t gt s}”>
<c:set var=”q” value=”${t-z}”></c:set>
<sql:query var=”d” sql=”select * from orderbooking_trans ${q},10″></sql:query>
<c:forEach var=”x” items=”${d.rows}”>
<tr><td>${x.Order_Id}</td><td>${x.Prospect_Id}</td><td>${x.Emp_Id}</td>
<td>${x.Order_date}</td><td>${x.Subvention}</td><td>${x. Margin}</td>
<td>${x.Spl_Offers}</td><td>${x.Dsa_Payout}</td><td>${x.FleetAmt}</td><td>${x.TotalOutFlow}</td>
<td>${x.TotalInFlow}</td><td>${x.TotalCosttoDlrship}</td><td>${x.CustType}</td>
<td>${x.ModeOfPurchase}</td><td>${x.FSource_Id}</td>
<td>${x.Paper_Fleet}</td></tr>
</c:forEach>
</c:if>
<c:if test=”${max ne false}”>
<td border=”0″><h2><font color=”red”>No Records </font></h2></td>
</c:if>

</table>

<table border=”0″ align=”center”>
<tr>

<c:set var=”c” value=”${s}”></c:set>
<c:set var=”p” value=”${f}”></c:set>
<c:if test=”${p gt 0 or p eq 0}”>
<td>&nbsp;<a href=”index.jsp?id=${p}”><<<<</a></td>
</c:if>

<c:forEach var=”v” begin=”0″ end=”${temp}” step=”10″>

<c:set var=”i” value=”${i+1}”></c:set>

<c:if test=”${v ne temp or v eq temp}”>
<c:if test=”${max eq false}”>
<td>&nbsp;<a href=”index.jsp?id=${v}”>${i}</a></td>
</c:if>
</c:if>
</c:forEach>

<c:if test=”${max eq false}”>

<td>&nbsp;<a href=”index.jsp?id=${c}”>>>>></a></td>
</c:if>

</tr>
</table>
<p>&nbsp;</p>

</center>

 

</body>
</html>