tesuji 135 Master Poster

Hello arbazpathan,

primary-key property is not required for table "vendor" if its "vendor_name" is already declared to be unique. If so, you can easily put a foreign-key constraint on table "purchase_order" referencing vendor(vendor_name) by means of "create table purchase_order(...)" or by "Alter table purchase_order ..." if table "purchase_order" already exists.

However, I am afraid that both tables already exist containing some data records, and, unfortunately, "vendor_name" of "vendor" is not declared to be unique. If so, your database design is inappropriate to model an one-to-many relationship correctly.

As adam_k already stated, a SQL trigger-program could be a good work-around.

I've got the feeling that there might be other potential solutions, as for example when checking whether entries in vendor table exist or not might happen within a procedural Java or PHP program.

So it would be a good idea to show more details by posting the really complete creation-statements of both tables "vendor" and "purchase_order" and also appropriate SQL statements for your wanted data processings.

-- tesu

tesuji 135 Master Poster

Hi

great!

click on the SQL icon in the tool bar. the icon looks like a small magnifying glass or sometimes like a piece of paper with a pen (depending on the versions).

I wish you good luck

-- tesu

tesuji 135 Master Poster

Hello

Greetings from the hood.

PL/SQL is Oracle's extention to SQL. It is similar to PSM the standardized ANSI SQL programming language. Actually many of the new features of PSM standardized in 1999 and 2003 were derived from PL/SQL. In my opinion, If one plans to work in the field of Oracle databases, PL/SQL is a must. Also postgresql and maxdb (Oracle clone from SAP) are based on PL/SQL.

As for SAP, I assume you are meaning R/3 or mySAP, it has its own programming language ABAP (formerly "Allgemeiner Berichtsaufbereitungsprozessor" now "Advanced Business Application Programming") derived from Cobol. Seriously doing development (customizing etc.) requiere good knowledge in ABAP and its workbench. Since 2004 when Plattner left SAP also Java has been defined to be co-equal programming language to ABAP.

That fits the bill for in 2003 the SQL committee has appointed Java to be the coming programming language for SQL databases. Unfortunately, there are only a few database vendors so far which support Java in SQL/Databases, for example: Oracle, IBM, Sybase.

For the long term Java will become the most important language for databases (=Oracle) and for R/3 & mySAP.

So doing business on both fields Oracle and SAP one should have good knowlegde in PL/SQL, ABAP and increasingly Java.

Notes: Besides PL/SQL or PSM there are other very mportant languages, for example C, C++, Java, PHP depending on the interface (ODBC, ADO, JDBC, embedded SQL). One should also consider that PL/SQL and …

tesuji 135 Master Poster

Hi

obviously is your storage engine not innodb, for example it could be myisam. If so, then foreign-key definitions are useless. Indeed, mysql allow you to define foreign keys, however they won't be processed, kinda everlasting bug or so!

Except your are using storage engine innodb which know them.

It is always a good idea only to using innodb, here the policy "ON DELETE CASCADE" works fine and much more other things other storage engines lack of.

-- tesu

tesuji 135 Master Poster

Hi muppet

CASE is kind of function which is only allowed to return a constant value. However with "'07:20:00' and '15:19:59'" you return part of an executeable sql statement (AND) what is illegal. Actually, mysql must notify an error yet remains silently.

Also experts then rubbing their eyes in disbelief for their statement is considered to be correct by the mighty system though the result is absurd ("...note the time in the timestamp is outside of where it should be.")

However that be, you could try this modified query:

select day(timestamp) as tamp, tech, packer_l, packer_r,  (packed_l + packed_r) as packed, timestamp as ts
 FROM abm_status
  where
   (
   case
     when (time(timestamp) between '07:20:00' and '15:19:59') then 'day' 
     when (time(timestamp) between '15:20:00' and '23:19:59') then 'swing' 
     else 'night' 
   end 
     
   =
   
   case
     when (time(now()) between '07:20:00' and '15:19:59') then 'day' 
     when (time(now()) between '15:20:00' and '23:19:59') then 'swing' 
     else 'night' 
   end
   )
   and tech != ''  
   and tech != 'Dummy Login' 
   and YEAR(timestamp) = YEAR(CURDATE()) AND MONTH(timestamp) = MONTH(CURDATE())
   order by packed desc; /* limit 1  ;*/

Please tell me whether this will work successfully, also what modifications you did to get it going.

Hint: You can't write that: "(time(now()) between '23:20:00' and '07:19:59')". Also this is formally incorrect for the left boundary must always be less or equal to the right one, usually you don't get an error reported, even on Oacle database. Neither you can interchange the boundaries. Instead you should write:

(time(now()) between …
tesuji 135 Master Poster

hi

what will happen if you omit "and CabRego='" & Me.cmbcabs.Text & "'" ?

what should be the meaning of & ?

Can you give all columns and their datatypes of table AccDtl?

-- tesu

tesuji 135 Master Poster

Thanks, I've found it! It's called EAV model:
Here is a little teaser: http://pratchev.blogspot.com/2010/07/refactoring-entity-attribute-value.html
And here is a little brighter objective (but much longer) description: http://en.wikipedia.org/wiki/Entity-attribute-value_model
As I understand, EAV doesn't violate any NF because it's not a relational design.

Hello MoZo1

Thanks a lot. To date, I haven't known that this concept would really have an official name, Entity-Attribute-Value model, EAV. And it is indeed frequently used in that odd MUMPS language. Actually, mid of the 1990th I introduced it when I was designing the database system for the Hewlett Packard CAD systems.


-- tesu

tesuji 135 Master Poster

Hello again

He, what about the 66 whales, could any of them be rescued?

Hell yeah, '07:20:00' AND '15:19:59' evaluates to 1! I have never seen other database systems than mysql doing seriously boolean algebra on time strings! Though this be kind of compensation for the below rough violation of ANSI SQL standard aliases? (now() of 1st line can differs from 2nd and 3rd lines ones!)

No, your case is not correct. I would make use of such a construct:

select time(now()) as "too sad, mysql cannot use this alias elsewhere",
case 
  when (time(now()) between '07:20:00' and '15:19:59') then 'The early bird catches the worm'
  when (time(now()) between '15:20:00' and '23:19:59') then 'We are from swinging' 
  else 'Nighty night everyone!'
end as "what a pitty";
/*
too sad, mysql cannot use this alias elsewhere  what a pitty
--------------------------------------------------------------------
15:50:42                                        We are from swinging

*/

-- tesu

(btw, a practial example like your earlier one would help much)

d5e5 commented: Good simple example of CASE syntax that does allow BETWEEN condition. +1
tesuji 135 Master Poster

>>> MoZo1
The values are stored as varchars. This is quite common. I only make use of two kernel SQL features which allow (1) that values be stored as strings independingly of their individual datatypes and (2) that casting by way of kernel function cast() be possible to convert from all standard datatypes (except of BLOP etc) into varchar and vice versa (which is not possible in to-day mysql due to nasty bugs still pending since 2007). Casting between datatypes does not violate any normalization rule, as far as I know.

>>> dino2dy
I don' think that everybody in here is fallen deep sleep. Well, your posted diagram is useless for one cannot use it to understanding your concept, for formally checking dependencies/relationships nor can't be basis for discussion. This is not a matter of language but solely of low resolution of screen shot.

I have already introduced a functional concept in principle on how to manage heterogen properties of general objects what hasn't been sketched in passing. By contrast, it's widely used for such issues, for example in implementing DIN4000. So far I don't know whether it might be useful for your sort of problems nor if you to design a new solution or be bound to already existing structures.

-- tesu

tesuji 135 Master Poster

Hello

If your problem is still existed, you may check whether TNSNAMES.ORA is in your directory path. There could also be discrepance between SQLNET.ORA and TNSNAMES.ORA. You could post both files here (make copy of them and replace your private data). Well, I am not an ora admin, just working with it, nevertheless I am trying to help you.

Where is our friend Deabsis Das? He is true Oracle expert and can help you instantly.

-- tes

tesuji 135 Master Poster

Hello Garrett85

Congratulations that you started to learn SQL from this great book Simply SQL written by my friend Rudy Limeback! This is the finest book for beginners I ever read. Clearly and precisely written, covering all important aspects of (DML-) SQL, contains a wealth of useful examples and tips, thoroughly founded on Rudys comprehensive experiences on database field.

Yes, it is "The fun and easy way to learn best-practice SQL".

I am sure that Rudy will add a small chapter on DDL-SQL to the next edition, the only very little SQL-part I am really missing from his wonderful book.

As for MySQL workbench you have already downloaded, assuming you have installed Ubuntu 10.04 (lucid) then workbench version must be 5.1.xx which does not have integrated Query SQL broswer to execute simple SQL statement like SELECT * FROM ... nor it has mysql administration functionality. However, it is possible to build version 5.2, which contains query and admin, from the sources. I have tested 5.2 new functionalities and in my opinion it is still in a very beta state. Of course, it is a good tool for designing kind of entity relationship models (ERM, not EER), much more better than its old error-prone predecessor (V4.2) from source-forge.

However, the most important thing is, you need to install a standard SQL database first, if you don't have already done this job. So what database for beginners?

Well, if you complete Rudy's book, you will have …

lewashby commented: Very helpful +1
tesuji 135 Master Poster

>>> How can I do this?

-- how many orphans ?
select count(*) as `so many orphans:` from rlbbulbs where brandID not in (select brandID from rlbbrand);

Again, if foreign key column brandID of rlbbulbs contains values other then NULL, which are not stored in column brandID of rlbbrand, you cannot add foreign key constraint to table rlbbulbs afterwards by means of simply altering table.

If you drop foreign key definitions, you should be clear that:

# each user data entry can destroy referential integrity,

# sooner or later your boss will get aware of that garbage data you are responsible for (except you are the boss yourself),

# to avoid garbage data you have to do considerably extra programming everyplace your application is modifying table rlbbulbs.

Ask yourself: Can I put stock in garbage data to seriously making money?

-- tesu

tesuji 135 Master Poster

actually ur code is recursive.. I want to implement divide and conquer using recursion.. My maxi function divides the problem into sub problems and then find the maximum and minimum for that sub problem... In the merge function am combining all the sub solutions obtained and thus am able to get a maximum and minimum for the given problem...

Oh I see, thank you so much for teaching me that my algorithm is not "the correct algorithm that follows divide and conquer technique"!

I have only divided twice and actually forgotten to conquer. So I say sorry for this slip-up.

-- tesu

tesuji 135 Master Poster

Hello

Now I have put my idea into an ERD. It is based on those two requirements:

(1) Each physically existing equipment must be associate to the store where it is located.

(2) There are various sorts of equipments where every sort is described by its own set of properties.

First requirement is represented by table storeequipement which has its own primary key although it seems to be a true many-to-many relationship between store and equipment. However, for there are stores having multiple equipments in the same line the pair (storeID, equipmentID) occurs repeatedly. One could add this pair to primary key too, what will allow faster table joining.

Second requirement is given by tables equipment and specificequipmentdata. Equipment holds all common data of equipments varieties. Specialized data of those varieties are hold in table specificequipmentdata. This is some kind of isa-relationship of generalization/ specialization from OO as MoZo1 already noted. Eventually, foreign key equipmenttypID should be added to specificdatatype for clearer grouping.

In my prior posting was a bad mistake, I couldn´realize the isa approach correctly. I have also chosen some more universally valid terms and names to develop the ERD.

Well, that´s it.

-- tesu

tesuji 135 Master Poster

Hi

sorry, i have overlooked this nice oracle tool. I have some idea for a solution how to manage your heterogen data based on the little model I gave. Principle Idea: handle all your equipment like in a retail system, customers are your stores. Game machines, internet connections are the material a la SAP R/3 etc.

I'll drawn a ERM in principle for you, now I am off, will be back in the late afternoon.

-- tesu

tesuji 135 Master Poster

Hello srinivasan,

below little code uses recursively called functions to determine min/max of an integer sequence. It works quicksort-like. I am not sure whether this is a useful solution to your problem.

int mini(int n, int ar[])
{
   int ml, mr, nh = n / 2;
   if( n == 1 ) return ar[0];
   ml = mini(nh, ar); mr = mini(n - nh, ar + nh);
   if ( ml < mr ) return ml; else return mr;
}
int maxi(int n, int ar[])
{
   int ml, mr, nh = n / 2;
   if(n == 1) return ar[0];
   ml = maxi(nh, ar); mr = maxi(n - nh, ar + nh);
   if ( ml > mr ) return ml; else return mr;
}
int mima()
{
   int ar[] = {10, 6, 9, -99, 99, 999, -98, 998, -10} ;
   cout << "min: " << mini(9, ar) << "  max: " << maxi(9, ar) << endl;   
   // min: -99  max: 999
   return 0;
}

try it, it should function.

Why do you need an additional merge function?

-- tesu

tesuji 135 Master Poster

Hello

Greetings from the hood!

Assuming you want to manage individual data for every occurrence and type of gaming machine you have installed on variuos stores you can do that by a one-to-many relationship between stores (table store) and indivudual data (table machinedata) and a many-to-many relationship between individual data and type of gaming machine (table machinetype).

store -----< machinedata >-----< machinetype


Sorry, the rest contains an mistake, therefore

**** deleted ****

I will answer you asap if that mistake is cleared.


Btw, it is a good idea to draw an entity relationship model of such data model, visual paradigm or even workbench of mysql are nice tools. With ERM one can see much more than only reading from written specifications.

-- tesu

tesuji 135 Master Poster

XP is a pretty good OS. No reason for changing it. Regardless of your future database wouldn't it a good idea to install service pack 3? Consider, MS has stopped further development of XP, there are only security-updates, so sp3 is important.

-- tesu

tesuji 135 Master Poster

Hi

Glad to meet you again.

In your code you only manipulate the lower 16 bits of eax, ebx and ecx by subtracting 16 bit regs. So the upper 16 bits contain random digits.

You should clear them:

mov eax, 0
mov ebx, 0
mov ecx, 0
;; then your subtractions here

However, only sub cx, bx will be correct for 8000H is already a negative number ! See: 8000H = 1000 0000 0000 0000B. The leading 1 (MSB) tells that this is a negative number in two's complement. If you deduct a positive number 2000H from a negative number 8000H the result is more negative. If not, then an overflow has occurred. Can you figure out the correct result of 8000H - 2000H ? Indeed, an overflow and a funny result will occur. (You may check OF flag.)

So simply change 8000H into 5000H (0101 0000 0000 0000) which is a positive number.

-- tesu

tesuji 135 Master Poster

>>> Question: Let's say there are 50 achievements. So this means every time a new account is created, I must create 50 new records in the userachievement table (1 for each achievement for that new user)?


Oh no! You may have stored thousands users and thousands achievements in both your tables users and achievement. An entry in table userachievement must only be made if the concerned user has indeed earned that specific achievement.

Exception from that rule: If every new created user has already earned all those 50 achievements, yes, then you have to do this tedious job :)

-- tesu

I also assumed that a user cannot earn same achievement twice, therefore no duplicate primary keys.

tesuji 135 Master Poster

Hi

>>> s for 8086 AND THE TURBO ASSEMBLER, tasm

Here could you find some tasm-like code what I posted related to similar problem, especially the inbuffer definition, the int 21h function 0AH and offset fit real mode tasm/masm well. Keep in mind, that code not tested.

-- tesu

tesuji 135 Master Poster

Primarily it depends on you operating system. On 32 bit windows there are "only" 2G bytes per process. So your max. array size would be a little less that 2GB. Also visual c++ 2005 is a 32 bit system. You may also consider that a double needs 8 bytes thus 2x10^9/8 makes about 2.5x10^8 double matrix elements.

If you need more, you should use 64 bit Linux system on 64bit hardware. Sometimes one can simulate large arrays with files.

-- tesu

tesuji 135 Master Poster

Hello

Developer version can be downloaded here. It doesn't matter whether you use V11.0.1 or V12.0.0. However, V11.0.1 is absolute stable (you should update to newest EBF, express bug fix) and V12.0.0 has been out for some months and doesn't support all languages, only English so far. I have both running on Linux, and they are absolutely stable. I have forgotten to mention in my prior posting that sqlanywhere v12 already supports many of the new ANSI SQL2008 standards.

You will get a developer key per email, what you will have to enter when install it.

btw, what is your operating system?

--tesu

tesuji 135 Master Poster

Hello

Assuming that

1st, a user may have earned 0, 1 or more achievements

and

2nd, an achievement may have been earned by 0, 1 or more users

then a many-to-many relationship exists between user and achievement. So your data model consists of three tables:

user(userID, name, etc)
achievement(achievementID, description, etc)

and

a so-called linking table which defines the many-to-many relationship:

userachievement(userID, achievementID, date, remark, etc)

Implementing this little data model on mysql (which is not a good database system for beginners) require that all primary keys and foreign keys be correctly defined. This is a must!

You should follow these suggestions:

create table user(
  userID int not null auto_increment, 
  name varchar(100) not null,
  primary key (userID)
);

create table achievement(
  achievementID int not null auto_increment, 
  description varchar(100) not null,
  primary key (achievementID)
);

create table userachievement(
  achievementID int not null auto_increment, 
  userID int not null auto_increment, 
  date timestamp,
  remark varchar(100),
  primary key (userID, achievementID),
  foreign key (userID) references user(userID),
  foreign key (achievementID) references achievement(achievementID),
);

-- above code NOT tested, so there could be typos!

Important: There is no (contra-productive) auto-incremented ID column in the many-to-many linking table! So never add such stuff to that sort of tables.

Don't omit any of the above key-definitions. They are all essential. If primary key (userID, achievementID) is not unique, what rarely happened sometimes, we should discuss how to solve this wee problem.

It is not necessary …

tesuji 135 Master Poster

Hi

>>> Also I though I would ask is it possible to replace the callback function with just the integer 0 as I have been doing or is there something special with the callback function?

The link given by gerard4143 shows an example where callback function isn't further necessary (modern version of SQLite in 5 Minutes)

-- tesu

Ancient Dragon commented: right +33
tesuji 135 Master Poster

Well, Oracle went to the Internet with version 8i (i for Internet). That happened in 1999. Since then there were versions 9i, 10g, and 11g in 2007.

So 8i is somewhat outdated. There have been dramatic improvements since 8i. If you want to stay with Oracle, I suggest free 10g express version (there isn't 11g express so far).

If you have free choice, I suggest to try free Sybase SQL Anywhere V12 developer (which is, in my opinion, simply the best for beginners), a complete database system, almost 100% ANSI SQL 1999/2003 (no fakes and flaws a la mysql), programable in almost all languages (ada, fortran, cobol, c, c++, Java, mumps, php, perl, ruby, .net, jsp ...), runs on Windows, Linux, Mac, is embedable, leading product in mobile computing..., MS SQL Server is derived from Sybase (licenced in 1995), however Sybase is more modern and has better coverage of ANSI SQL, (no, I am not an agent of Sybase).

-- tesu

tesuji 135 Master Poster

+++ deleted +++
Sorry, you aren't allowed to use two-dimensional arrays, so my posting is useless !
+++ deleted +++

tesuji 135 Master Poster

Hello

I would suggest to use a standard sql database instead of programming all those insert/update/delete functionalities by yourselves. There was a similar question recently. You may read here what I wrote.

To keep it small I suggest to embed a database system into your C++ program. The most embedded database is SQLite3, for example in Mozilla Firefox, Open Office, Skype etc. It is probably the most frequently applied database system worldwide. SQLite3 is easy to handle and very simple to integrate in C++ programs yet it is an almost complete rational database system based on SQL1999/2003.

-- tesu

tesuji 135 Master Poster

Hi

>>> Or do i leave the 4 existing items where they were and put the two new items in elements [0] and [1] ?

Yes, for it is a circular buffer, and as Momerath already stated "store the new value at the 'next' pointer and increment it modulus the size of your array".

Here is a good explanation on how a circular buffer functions.

-- tesu

tesuji 135 Master Poster

There is a great book about C++ and GUI programming by Jasmin Christian Blanchette of trolltech dot com. His book, well, about 60 USD, also older versions are available, is great for learning QT (cute). Following his tutorial you will have learnt the very basics of GUI programming within ten minutes, and probably you won't make use of any other C++ GUI system than that portable QT for windows, unix, mac.

-- tesu

tesuji 135 Master Poster

Hi

your task can easily be solved by means of a sub-select, in principle:

select * from yourtable 
  where sequence in (select max(sequence) from yourtable group by ...) order by ...;

Now your personal task is to figure out how group-by and order-by clauses must look like to meet your requirements. It's easy, try it with studid, class and also sequence for the latter clause.

There are other ways to solve your problem, for example with OLAP methods. Here I wrote something about using window function row_number() with partitioning, but your problem is much easier than his one.

Shall that be an assignment, I would suggest to get rid of this unnatural column "Sequence", obviously also auto-incremented, by introducing the date the exam took place. Then you would also have a perfect primary key (studid, class, date).

-- tesu

tesuji 135 Master Poster

Hello

in principle, it goes that way

select yourData from yourtable
  where datediff (day, s1, now()) <= 10;

Now it's your turn to put some c# code around the sql statement.

You may show your result for further discussions.

-- tesu

tesuji 135 Master Poster

Hello

mysql isn't a simple database system! It does the job very well introducing a foreign key for tables rlbbrand (father) and rlbbulbs (son) by way of an ALTER statement, even if both have already inserted rows !!! Like Oracle and DB/2 it also obtrusively checks whether each foreign key stored in rlbbulbs also has its father in rlbbrand. If there is an orphan, the following error message arises:

Cannot add or update a child row: a foreign key constraint fails (`teedoff`.`#sql-20ff_29`, CONSTRAINT `#sql-20ff_29_ibfk_1` FOREIGN KEY (`brandID`) REFERENCES `rlbbrand` (`brandID`))

You may check your table rlbbulbs whether there are orphans. Such things could happen if foreign keys are not properly defined.

Here is some code to prove how clever mysql is:

Create Table rlbbrand(
                                          brandID int NOT NULL AUTO_INCREMENT,
 brandName varchar(255) DEFAULT NULL,
                                          PRIMARY KEY (brandID)
);
insert into rlbbrand (brandName) values ('First');
insert into rlbbrand (brandName) values ('Second');
insert into rlbbrand (brandName) values ('Third');
commit;
select * from rlbbrand;

CREATE TABLE rlbbulbs (
                                         bulbID int(11) NOT NULL AUTO_INCREMENT,
 item char(255) DEFAULT NULL,
                                         brandID int(11), -- ------ NOT NULL usually not necessary
 
                                          PRIMARY KEY (bulbID)
                                     --    ,FOREIGN KEY (brandID) REFERENCES rlbbrand(brandID) 
);
insert into rlbbulbs (item, brandID) values ('References Second', 2);
insert into rlbbulbs (item, brandID) values ('References First', 1);
insert into rlbbulbs (item, brandID) values ('References does not exists', 33); -- <---- should not allow to execute below alter statement

commit;
select * from rlbbulbs;

alter table rlbbulbs add foreign key (brandID) references rlbbrand …
tesuji 135 Master Poster

He, I have forgotten to mention that the table where you want to add a foreign key by ALTER statement usually must be empty. Also referenced table could be required to be empty too, especially on simple database systems.

-- tesu

tesuji 135 Master Poster

No, you can copy the code from daniweb MySQL Syntax (Toggle Plain Text) to phpmyadmin and complete it by the lines I dropped, sorry for that.

(Usually I don't use mysql for serious projects :) )

tesuji 135 Master Poster

Here is it:

Create Table rlbbrand(
                                          brandID int NOT NULL AUTO_INCREMENT,
 brandName varchar(255) DEFAULT NULL,
                                          PRIMARY KEY (brandID)
);

show create table rlbbrand;

CREATE TABLE rlbbulbs (
                                         bulbID int(11) NOT NULL AUTO_INCREMENT,
 item char(255) DEFAULT NULL,
                                         brandID int(11), -- ------ NOT NULL usually not necessary
 
                                          PRIMARY KEY (bulbID),
                                          FOREIGN KEY (brandID) REFERENCES rlbbrand(brandID) 
);
commit

show create table rlbbrand;
CREATE TABLE `rlbbrand` (
  `brandID` int(11) NOT NULL AUTO_INCREMENT,
  `brandName` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`brandID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

show create table rlbbulbs;

CREATE TABLE `rlbbulbs` (
  `bulbID` int(11) NOT NULL AUTO_INCREMENT,
  `item` char(255) DEFAULT NULL,
  `brandID` int(11) DEFAULT NULL,
  PRIMARY KEY (`bulbID`),
  KEY `brandID` (`brandID`),
  CONSTRAINT `rlbbulbs_ibfk_1` FOREIGN KEY (`brandID`) REFERENCES `rlbbrand` (`brandID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
select version();

My prior posting contained some mistakes I already corrected them now. Above code it the exact copy from tora editor and executed without any error.

There is also a screen shot.

tesu

tesuji 135 Master Poster

Hi

I just did creating both tables on mysql 5.1.41-3ubuntu12.6 using tOra 2.1.1, and it works:

Create Table rlbbrand(
                                          brandID int NOT NULL AUTO_INCREMENT,
 brandName varchar(255) DEFAULT NULL,
                                          PRIMARY KEY (brandID)
);

show create table rlbbrand;

CREATE TABLE rlbbulbs (
                                         bulbID int(11) NOT NULL AUTO_INCREMENT,
 item char(255) DEFAULT NULL,
                                         brandID int(11), -- ------ NOT NULL usually not necessary
 
                                          PRIMARY KEY (bulbID),
                                          FOREIGN KEY (brandID) REFERENCES rlbbrand(brandID) 
);
commit

show create table rlbbrand;
CREATE TABLE `rlbbrand` (
  `brandID` int(11) NOT NULL AUTO_INCREMENT,
  `brandName` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`brandID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

show create table rlbbulbs;

CREATE TABLE `rlbbulbs` (
  `bulbID` int(11) NOT NULL AUTO_INCREMENT,
  `item` char(255) DEFAULT NULL,
  `brandID` int(11) DEFAULT NULL,
  PRIMARY KEY (`bulbID`),
  KEY `brandID` (`brandID`),
  CONSTRAINT `rlbbulbs_ibfk_1` FOREIGN KEY (`brandID`) REFERENCES `rlbbrand` (`brandID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
select version();

There was a little typo in the word "REFRENCES".


-- tesu

tesuji 135 Master Poster

As for your both tables:

Create Table rlbbrand 
 TABLE `rlbbrand` (
                                          `brandID` int(11) NOT NULL AUTO_INCREMENT,
 `brandName` varchar(255) DEFAULT NULL,
                                          PRIMARY KEY (`brandID`),
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=latin1

Table  Create Table rlbbulbs 

CREATE TABLE `rlbbulbs` (
                                         `bulbID` int(11) NOT NULL AUTO_INCREMENT,
 `item` char(255) DEFAULT NULL,
                                         `brandID` int(11), -- ------ NOT NULL usually not necessary
 `bulbDesc` longtext,
 `cost` text,
 `price` text,
 `qtyPerPrice` char(100) DEFAULT NULL,
 `wattage` char(255) DEFAULT NULL,
 `voltage` char(255) DEFAULT NULL,
 `base` char(255) DEFAULT NULL,
 `glass` char(255) DEFAULT NULL,
 `filament` char(255) DEFAULT NULL,
 `avgLife` char(255) DEFAULT NULL,
 `beamAngle` char(255) DEFAULT NULL,
 `catagory` char(255) DEFAULT NULL,
 `oldPage` char(255) DEFAULT NULL,
 `keyWords` longtext,
 `image1` char(255) DEFAULT NULL,
                                          PRIMARY KEY (`bulbID`),
                                          FOREIGN KEY brandID REEFRENCES rlbbrand(brandID) 
) ENGINE=InnoDB AUTO_INCREMENT=1595 DEFAULT CHARSET=latin1

Don't get confused with other unique or not-unique indexes/keys. You only need such stuff if you have to manage many many rows and the performance is going down. Also foreign keys usually don't need extra indexes, except for many-to-many relationships.

The most important thing is that all primary keys as well as all foreign keys be correctly defined.

As for foreign keys of one-to-many relationships: My above suggestion denotes the common case of such applications The foreign brandID key is so-called "non-identifying" in table rlbbulbs, that is, it is NOT a member of the primary key of rlbbulbs. Sometimes it is necessary that the foreign key also become member of the primary key, thus identifying foreign key. This case is considerably rarer and depends on the specific application.

tesuji 135 Master Poster

Hello

obviously there is a one-to-many relationship between table rlbbrand and table rlbbulbs. That means from the view point of rlbbrand that there are many rows of rlbbulbs could be related to. From the view point of rlbbulbs a specific row can be related to only one row of rlbbrand.

"Graphically" it is: rlbbrand -------< rlbbulbs, where --<, also named crowfoot, points to the table,rlbbulbs, where the primary from the related table, rlbbrand, moves in and become here a foreign key.

Therefore table rlbbulbs must have the following objects at least:

brandID int -- not necessary: not null
and
foreign key brandID references rlbbrand(brandID)

There is nothing more!

No, I assumed that the other guys would have already solved your problem, usually I don't meddle in into advanced discussions.

-- tesu

tesuji 135 Master Poster

Hi

pushl is a 32 bit instruction (suffix l = long = 32bit). So the assembly is wrong for 64bit machines, except you do special compiling and linking with gcc and ld. You need to tell the compiler and the linker that you would like to get 32bit-code. For the compiler there is the -m32 option. Then you should do separate linking with ld. Here you must specify only 32 bit libraries! Then the result should run on 64bit systems too.

I personally would hardly start to learn assembly programming with that exotic syntax of gasm, Just consider the prefixes $ and % for variables, constants and registers. Also the order of operands is quite opposite to the rest of the world which follows IBM convention, for example MASM, MASM32, TASM, NASM, Intel ASM, WASM admit MOV DESTINATION, SOURCE, whereas gasm and the archaic ideal mode of TASM follow MOV SOURCE, DESTINATION. Furthermore the addressing modes of gasm are really exceptional as compared with the rest of intel assembly world.

To cut this long story short, I would use NASM to learn assembly programming from ground up.

-- tesu

tesuji 135 Master Poster

You could try this:

String[] names = {"joe", "slim", "ed", "george"};
Arrays.sort(names);
System.out.println(Arrays.toString(names));

Sorry, meanwhile you have changed your posting.

-- tesu

tesuji 135 Master Poster

Maybe you replace INSERT by something like this:

update products set quantity = quantity - quvalue_from_admin_list 
  where id_quantity = idvalue_from_admin_list

This would somewhat coincide with your other posting.

I have assumed that your admin's list is a sales list, therefore quantities on stock must be reduced by sold amounts.

-- tesu

tesuji 135 Master Poster

You need something like that:

update products set quantity = quantity - quvalue_from_admin_list 
  where id_quantity = idvalue_from_admin_list

Obviously, in PHP code from your other posting you also need to replace INSERT by above UPDATE ...

-- tesu

tesuji 135 Master Poster

Hello

The cos-function y = cos(x) gives a value y which is from [-1 ... +1]. Its parameter x must be radians, that is for example -2*pi ... +2*pi, also values > 2*pi are allowed.

Therefore the parameter y of the restricted inverse function x = acos(y) must always be from [-1 ... +1]. x is then from restricted domain [pi .. 0] because cos is periodic.

As for your program:

>> a=Integer.parseInt (args[0]);
a can be a parameter for acos function if a is from [-1..+1]. If not, NaN would be the result.

>> b=(float)Math.acos(a*(180/3.14));
should be: b = Math.acos(a);
The result b is radians. You can convert it into degrees: b_degrees = b * 180 / pi or b_degrees = Math.acos(a) * 180 / pi, where pi = 3.14159265358979 or 4*atan(1).

-- tesu

tesuji 135 Master Poster

Here can you find additional information about ORG directive.

-- tesu

tesuji 135 Master Poster

Hello

There is something more to do.

Hint: First add a column to your table which simply indicates present and absent booking timestamps. Below is an example of a table with computed column isPresent and ordered by PersonalNumber what I had already published elsewhere:

/*
PersonalNumber  BookingStamp             isPresent
--------------------------------------------------
1000            2009-08-11 07:12:05.000  1
1000            2009-08-11 09:10:00.000  0
1000            2009-08-11 10:08:29.000  1
1000            2009-08-11 18:31:01.000  0
2000            2009-08-11 08:56:00.000  1
2000            2009-08-11 19:00:00.000  0
2000            2009-09-09 09:08:07.000  1
2000            2009-09-09 15:18:00.000  0
3000            2009-08-10 07:30:05.000  1
3000            2009-08-10 17:00:57.000  0
3000            2009-08-11 12:12:12.000  1
*/

If this additional column is given, selecting present and absent booking timestamps in same row together with corresponding personal number can simply be achieved by various methods depending on database.

-- tesu

tesuji 135 Master Poster

Hello

I would do that with a user defined function or with any other .net programming language or even Java. Do you know Transact SQL, the SQL Server´s programming language which is very similar to standardized PSM language?

Below user defined function, written transact-like, should insert @nbofRows in column lotnumber of yourTable where every 25 units the lot number is increased by 1.

create function owner.lotsCards(@nbofRows int) returns int
as
begin
  declare @lot int;
  declare @lotsNumber int;
  declare @lotsUnit int;
  declare @nrow int;
  set @lotsUnit  = 25;                      -- The cards come in lots of 25 units.
  set @lotsNumber = @nbofRows / @lotsUnit;  -- the number of lots, 1000000/25=40000 lots
  message 'Number of lots: ' || @lotsNumber to client;            
  set @lot = 1;                  
  while @lot <= @lotsNumber loop            --  loop on all lots 
    set @nrow = 1;               
    while @nrow <= @lotsUnit loop           --  inserting 25 times same lot number, e.g. 0001
      /*** this insert statement should be adapt to your table and column ***/
      insert into owner.yourTable (lotnumber /*are there any other column too ? */) values (@lot);
      set @nrow = @nrow + 1;    
    end loop;
    commit;               -- every 25 inserts a commit is done. Important: if this function 
                          -- runs within larger tanscation, this commit MUST BE DROPPED!
    set @lot = @lot + 1;
  end loop;
  return @lotsNumber;
end;

You should change qualifier owner. and the create-statement to yours. This code hasn't been tested so there might by typos or even logical errors, pls check carefully.

tesuji 135 Master Poster

This algorithm is linear in time. On a 100000 x 100000 chess board it lasts about one second for medium-fast computer.

Possibly your program is running in endless loop.

-- tesu

tesuji 135 Master Poster

hello

you may try this:

select userid, personid, positionid, count(positionid) as cntpos from yourtable
  group by userid, personid, positionid having cntpos > 1;

btw, your table isn't that well normalized.

-- tesu

tesuji 135 Master Poster

Only starting hint, google this: generalization specialization relational modeling

Now it's your turn.

You may post in what you will then have decided, and we will discussing and possibly also improving your results.

-- tesu