Is it necessary to free a shared_ptr?
I'm using Boost library to benefit from the smart pointers : shared_ptr.
I suspect that in my unit test, i'm doing a bad assignment.
What are the drawbacks of my implementation, specially the instuction that
has //suspected comment?
Do I need to free shared_ptr pointers (impossible to do in the way i'm
assigning in my unit test, i guess)?
Any advice? Thanks a lot!
In Class2 declaration:
static boost::shared_ptr<Class1> getInstanceOfClass1();
In Class2 definition:
boost::shared_ptr<Class1> Class2::getInstanceOfClass1()
{
boost::shared_ptr<Class1> inst1 = boost::make_shared<Class1>();
//.... some instructions on inst1
return inst1 ;
}
In a Unit Test using Boost.Test:
BOOST_AUTO_TEST_CASE( test_some_label_here )
{
string input;
//instructions...
// mocking the input
//...
Class2 a = *(Class2::getInstanceOfClass1()); //suspected
int code = a.useInputAndReturnCode(input);
// having CODE_X as a macro
BOOST_CHECK_EQUAL(code, CODE_X);
}
Borbon
Thursday, 3 October 2013
Wednesday, 2 October 2013
How aright write query?
How aright write query?
Good day.
For my database i use next query.
Code:
SELECT TOP 20
ha.datetime as ha_date,
ha.id_hist_calls as ha_id_hist_calls,
ha.name as ha_name,
s.name as s_name,
ss.name as ss_name
FROM Hist_answer ha
left join Hist_calls hc on hc.id_hist_calls = ha.id_hist_calls
left join Service s on s.id_service = ha.from_id_service
left join Service ss on ss.id_service = ha.id_service
WHERE ha.id_hist_calls NOT IN (
SELECT
ha.id_hist_calls as ha_id_hist_calls
FROM Hist_answer ha
WHERE ha.id_firm='39273' AND ha.datetime BETWEEN '2010.06.01 00:00:000'
AND '2013.10.01 00:00:000'
ORDER BY ha.datetime ASC
)
AND ha.id_firm='39273'
AND ha.datetime BETWEEN '2010.06.01 00:00:000' AND '2013.10.01 00:00:000'
ORDER BY ha.datetime ASC
But when i use this query i get error:
Msg 1033, Level 15, State 1, Line 17
The ORDER BY clause is invalid in views, inline functions, derived tables,
subqueries, and common table expressions, unless TOP or FOR XML is also
specified.
How aright write this select?
Good day.
For my database i use next query.
Code:
SELECT TOP 20
ha.datetime as ha_date,
ha.id_hist_calls as ha_id_hist_calls,
ha.name as ha_name,
s.name as s_name,
ss.name as ss_name
FROM Hist_answer ha
left join Hist_calls hc on hc.id_hist_calls = ha.id_hist_calls
left join Service s on s.id_service = ha.from_id_service
left join Service ss on ss.id_service = ha.id_service
WHERE ha.id_hist_calls NOT IN (
SELECT
ha.id_hist_calls as ha_id_hist_calls
FROM Hist_answer ha
WHERE ha.id_firm='39273' AND ha.datetime BETWEEN '2010.06.01 00:00:000'
AND '2013.10.01 00:00:000'
ORDER BY ha.datetime ASC
)
AND ha.id_firm='39273'
AND ha.datetime BETWEEN '2010.06.01 00:00:000' AND '2013.10.01 00:00:000'
ORDER BY ha.datetime ASC
But when i use this query i get error:
Msg 1033, Level 15, State 1, Line 17
The ORDER BY clause is invalid in views, inline functions, derived tables,
subqueries, and common table expressions, unless TOP or FOR XML is also
specified.
How aright write this select?
Rescale an Image using Python3.2
Rescale an Image using Python3.2
I'm working on a python code that takes an image name from the command
line, and prints its, rescaled to the user's likings, i.e., the input
python3.2 resize.py image.gif 2 3 would take image.gif and double the
width and triple the height. I've written a code for quadrupling an image:
import sys
from cImage import *
def main():
oldImage = FileImage(sys.argv[1])
width = oldImage.getWidth()
height = oldImage.getHeight()
myWin = ImageWin("Old Image", width, height)
myNewWin = ImageWin("Quadrupled Image", width*4, height*4)
newImage = EmptyImage(width*4, height*4)
for r in range(width):
for c in range(height):
pixel = oldImage.getPixel(r, c)
newImage.setPixel(4*r, 4*c, pixel)
newImage.setPixel(4*r, 4*c+1, pixel)
newImage.setPixel(4*r, 4*c+2, pixel)
newImage.setPixel(4*r, 4*c+3, pixel)
newImage.setPixel(4*r+1, 4*c, pixel)
newImage.setPixel(4*r+1, 4*c+1, pixel)
newImage.setPixel(4*r+1, 4*c+2, pixel)
newImage.setPixel(4*r+1, 4*c+3, pixel)
newImage.setPixel(4*r+2, 4*c, pixel)
newImage.setPixel(4*r+2, 4*c+1, pixel)
newImage.setPixel(4*r+2, 4*c+2, pixel)
newImage.setPixel(4*r+2, 4*c+3, pixel)
newImage.setPixel(4*r+3, 4*c, pixel)
newImage.setPixel(4*r+3, 4*c+1, pixel)
newImage.setPixel(4*r+3, 4*c+2, pixel)
newImage.setPixel(4*r+3, 4*c+3, pixel)
oldImage.draw(myWin)
newImage.draw(myNewWin)
myWin.exitOnClick()
myNewWin.exitOnClick()
main()
But I am having trouble try to figure out how to edit my code so it scales
the parameters requested. I feel that I should probably be able to
implement a for loop, but I'm having a hard time getting things to work.
Any help would be much appreciated!
I'm working on a python code that takes an image name from the command
line, and prints its, rescaled to the user's likings, i.e., the input
python3.2 resize.py image.gif 2 3 would take image.gif and double the
width and triple the height. I've written a code for quadrupling an image:
import sys
from cImage import *
def main():
oldImage = FileImage(sys.argv[1])
width = oldImage.getWidth()
height = oldImage.getHeight()
myWin = ImageWin("Old Image", width, height)
myNewWin = ImageWin("Quadrupled Image", width*4, height*4)
newImage = EmptyImage(width*4, height*4)
for r in range(width):
for c in range(height):
pixel = oldImage.getPixel(r, c)
newImage.setPixel(4*r, 4*c, pixel)
newImage.setPixel(4*r, 4*c+1, pixel)
newImage.setPixel(4*r, 4*c+2, pixel)
newImage.setPixel(4*r, 4*c+3, pixel)
newImage.setPixel(4*r+1, 4*c, pixel)
newImage.setPixel(4*r+1, 4*c+1, pixel)
newImage.setPixel(4*r+1, 4*c+2, pixel)
newImage.setPixel(4*r+1, 4*c+3, pixel)
newImage.setPixel(4*r+2, 4*c, pixel)
newImage.setPixel(4*r+2, 4*c+1, pixel)
newImage.setPixel(4*r+2, 4*c+2, pixel)
newImage.setPixel(4*r+2, 4*c+3, pixel)
newImage.setPixel(4*r+3, 4*c, pixel)
newImage.setPixel(4*r+3, 4*c+1, pixel)
newImage.setPixel(4*r+3, 4*c+2, pixel)
newImage.setPixel(4*r+3, 4*c+3, pixel)
oldImage.draw(myWin)
newImage.draw(myNewWin)
myWin.exitOnClick()
myNewWin.exitOnClick()
main()
But I am having trouble try to figure out how to edit my code so it scales
the parameters requested. I feel that I should probably be able to
implement a for loop, but I'm having a hard time getting things to work.
Any help would be much appreciated!
how can I populate and retrieve table of record using java
how can I populate and retrieve table of record using java
Package, in which I declared my Data Types
create or replace package pkg_var is
type array_table is table of varchar2(50);
type array_int is table of number;
type p_arr_rec is record(p_no number,p_val varchar2(50));
type array_record is table of p_arr_rec;
end pkg_var;
/
My procedure to populate record
create or replace procedure proc1(p_array in pkg_var.array_table,
arr_int in pkg_var.array_int,len out number,arr_rec out
pkg_var.array_record)
as
v_count number;
begin
len := p_array.count;
v_count :=0;
for i in 1..p_array.count
loop
--dbms_output.put_line(p_array(i));
arr_rec(i).p_no := arr_int(i);
arr_rec(i).p_val := p_array(i);
v_count := v_count+1;
end loop;
end;
/
This is my class to call the above procedure to populate array into table
of record
public class TestDatabase {
public static void passArray()
{
try{
dbcon conn = new dbcon();
Connection con = conn.dbstate().getConnection();
String str_array[] = {"one", "two", "three","four"};
int int_array[] = {1, 2, 4,8};
ArrayDescriptor str_des =
ArrayDescriptor.createDescriptor("SCOTT.PKG_VAR.ARRAY_TABLE",
con);
ARRAY arr_str = new ARRAY(str_des,con,str_array);
ArrayDescriptor des =
ArrayDescriptor.createDescriptor("SCOTT.PKG_VAR.ARRAY_INT",
con);
ARRAY arr_int = new ARRAY(des,con,int_array);
CallableStatement st = con.prepareCall("call
SCOTT.proc1(?,?,?)");
// Passing an array to the procedure -
st.setArray(1, arr_str);
st.setArray(2, arr_int);
st.registerOutParameter(3, Types.INTEGER);
st.registerOutParameter(4,OracleTypes.ARRAY,"SCOTT.PKG_VAR.ARRAY_RECORD");
st.execute();
System.out.println("size : "+st.getInt(3));
// Retrieving array from the resultset of the procedure after
execution -
ARRAY arr = ((OracleCallableStatement)st).getARRAY(4);
BigDecimal[] recievedArray = (BigDecimal[])(arr.getArray());
for(int i=0;i<recievedArray.length;i++)
System.out.println("element" + i + ":" + recievedArray[i]
+ "\n");
} catch(Exception e) {
System.out.println(e);
}
}
public static void main(String args[]){
passArray();
}
}
I'm getting java.sql.SQLException: invalid name pattern:
SCOTT.PKG_VAR.ARRAY_TABLE Exception, anyone help me to solve this
exception.
One more question how do I retrieve table of record of SQL in Java ? My
second question is for this code ARRAY arr =
((OracleCallableStatement)st).getARRAY(4);
Is it a valid code to get table of record ?
Package, in which I declared my Data Types
create or replace package pkg_var is
type array_table is table of varchar2(50);
type array_int is table of number;
type p_arr_rec is record(p_no number,p_val varchar2(50));
type array_record is table of p_arr_rec;
end pkg_var;
/
My procedure to populate record
create or replace procedure proc1(p_array in pkg_var.array_table,
arr_int in pkg_var.array_int,len out number,arr_rec out
pkg_var.array_record)
as
v_count number;
begin
len := p_array.count;
v_count :=0;
for i in 1..p_array.count
loop
--dbms_output.put_line(p_array(i));
arr_rec(i).p_no := arr_int(i);
arr_rec(i).p_val := p_array(i);
v_count := v_count+1;
end loop;
end;
/
This is my class to call the above procedure to populate array into table
of record
public class TestDatabase {
public static void passArray()
{
try{
dbcon conn = new dbcon();
Connection con = conn.dbstate().getConnection();
String str_array[] = {"one", "two", "three","four"};
int int_array[] = {1, 2, 4,8};
ArrayDescriptor str_des =
ArrayDescriptor.createDescriptor("SCOTT.PKG_VAR.ARRAY_TABLE",
con);
ARRAY arr_str = new ARRAY(str_des,con,str_array);
ArrayDescriptor des =
ArrayDescriptor.createDescriptor("SCOTT.PKG_VAR.ARRAY_INT",
con);
ARRAY arr_int = new ARRAY(des,con,int_array);
CallableStatement st = con.prepareCall("call
SCOTT.proc1(?,?,?)");
// Passing an array to the procedure -
st.setArray(1, arr_str);
st.setArray(2, arr_int);
st.registerOutParameter(3, Types.INTEGER);
st.registerOutParameter(4,OracleTypes.ARRAY,"SCOTT.PKG_VAR.ARRAY_RECORD");
st.execute();
System.out.println("size : "+st.getInt(3));
// Retrieving array from the resultset of the procedure after
execution -
ARRAY arr = ((OracleCallableStatement)st).getARRAY(4);
BigDecimal[] recievedArray = (BigDecimal[])(arr.getArray());
for(int i=0;i<recievedArray.length;i++)
System.out.println("element" + i + ":" + recievedArray[i]
+ "\n");
} catch(Exception e) {
System.out.println(e);
}
}
public static void main(String args[]){
passArray();
}
}
I'm getting java.sql.SQLException: invalid name pattern:
SCOTT.PKG_VAR.ARRAY_TABLE Exception, anyone help me to solve this
exception.
One more question how do I retrieve table of record of SQL in Java ? My
second question is for this code ARRAY arr =
((OracleCallableStatement)st).getARRAY(4);
Is it a valid code to get table of record ?
Is there anyway to extract comments from facebook
Is there anyway to extract comments from facebook
I have project to extract the comments from Facebook and shows than we
will put behavior on it weather is in good mood happy mood sad mood
etc.Actually i don't have an idea where to is there any API available
which programing language will be good please give me a way .
I have project to extract the comments from Facebook and shows than we
will put behavior on it weather is in good mood happy mood sad mood
etc.Actually i don't have an idea where to is there any API available
which programing language will be good please give me a way .
Tuesday, 1 October 2013
Synology Mail server SMTP 535 error
Synology Mail server SMTP 535 error
Good day Ladies and Gentlemen! I don't know if I am allowed to do this,
this is not really a programming problem but a setup problem in my
synology mail server. I can receive mail but the problem is I can't send a
mail. My smtp relay is smtp.gmail.com with a port 587. I really need a
help. I googled it before but it seems that synology forums are not that
active. Thanks and God bless! My NAS is DS1512+
Good day Ladies and Gentlemen! I don't know if I am allowed to do this,
this is not really a programming problem but a setup problem in my
synology mail server. I can receive mail but the problem is I can't send a
mail. My smtp relay is smtp.gmail.com with a port 587. I really need a
help. I googled it before but it seems that synology forums are not that
active. Thanks and God bless! My NAS is DS1512+
I dropped a table in Oracle, how can I retrieve it from the undo tablespace?
I dropped a table in Oracle, how can I retrieve it from the undo tablespace?
I accidentally dropped a fairly large table -- recycling bin is not
enabled. I'm fairly certain the data still exists in the UNDO tablespace,
but I'm not sure how to get it out. I recreated the table exactly as it
was before it was dropped -- the structure is exactly the same. However,
when I attempt to flashback the table, I get this error:
flashback table tablex to timestamp (systimestamp - interval '120'
minute); Error: 01466 DBD::Oracle::db do failed: ORA-01466: unable to read
data - table definition has changed
Any idea how I can overcome this error? From all of the searching I've
done, it seems as if it believes the table is not structurally the same as
when it was dropped.
Thanks so much!
I accidentally dropped a fairly large table -- recycling bin is not
enabled. I'm fairly certain the data still exists in the UNDO tablespace,
but I'm not sure how to get it out. I recreated the table exactly as it
was before it was dropped -- the structure is exactly the same. However,
when I attempt to flashback the table, I get this error:
flashback table tablex to timestamp (systimestamp - interval '120'
minute); Error: 01466 DBD::Oracle::db do failed: ORA-01466: unable to read
data - table definition has changed
Any idea how I can overcome this error? From all of the searching I've
done, it seems as if it believes the table is not structurally the same as
when it was dropped.
Thanks so much!
Subscribe to:
Comments (Atom)