Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 346 347 [348] 349 350 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886024 times)

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5205 on: November 13, 2013, 04:22:39 am »

It's not production-appropriate, but there's always SQLite3. It's suitable for running locally and/or testing, though.

SQLite is really unsuitable (unusable?) for concurrent connections.

It should work plenty well enough for the sort of thing described.
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5206 on: November 13, 2013, 05:23:20 am »

So I'm now a CS major after a year at school and we just made a pretty basic "database" using classes and fstream. We had to make it search for song title and print the list of five "songs" that included title,artist,length and an extra variable we decide.

So I've started to make it work with pokemon.
Spoiler (click to show/hide)

There's a couple of debug and output formatting issues, but then with just a few modifications and extra switches I can make it load different regions.

Eventually maybe I'll detail evolution chains and learned moves. Is it too obvious I like databases and organization?

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5207 on: November 14, 2013, 06:00:39 am »

a neat free MongoDB database, but I'm scared to touch that
You should be. Good use cases for MongoDb are incredibly few and far between. Using it as a cache instead of a database is one of them. Using it to retain data that is even remotely interconnected is not one of them.

SQLite is perfect for your use case, I think. As long as you don't try to do too many (arbitrary numbers ho) writes at once you'll be fine.
« Last Edit: November 14, 2013, 06:04:35 am by Siquo »
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5208 on: November 14, 2013, 07:28:17 am »

In plant.h, forward declare SoilCell. In a header, you can use a class pointer or reference without including the class's header file.

The compiler just slaps me with the errors

Quote
error C2027: use of undefined type 'ALMANAC::SoilCell'
error C2227: left of '->requestWater' must point to class/struct/union/generic type
etc. requestWater() is a function inside SoilCell.

fake edit: I solved it by including soil.h in plant.cpp.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5209 on: November 14, 2013, 02:43:26 pm »

So I got the Reshaper for C++ Early Access. I'll say it is pretty neat. Unfortunately it doesn't recognise a lot of the new syntax yet, so no Variadic Templates for example, but it also offers some neat code inspections and in general looks very promising. At the moment it doesn't replace Visual Assist X, but it does supplement it very nicely. Once it gets more features and more C++11 support, it'll be an incredible tool. Can't wait to see what they have going on in their whole C++ IDE.
« Last Edit: November 14, 2013, 02:55:54 pm by MorleyDev »
Logged

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5210 on: November 18, 2013, 06:34:26 am »

I need some help with MySQL. I am creating a backend for a faux e-commerce site and am having some issues with adding a specific table.

I am using MySQL Workbench.

Basically I have a table for users containing a primary key called username, I also have a table for items in the store containing a primary key called item_id. Now I want to create a table called orders that amongst other things contain foreign keys pointing to the username and the item id. When forward engineering this, workbench throws the following extremely descriptive error.

"ERROR: Error 1005: Can't create table 'mydb.ORDERS' (errno: 121)"

I understand that this has something to do with the foreign keys and from google the reason seems to be foreign keys named the same as the constraint but I use the same thing for a table called Inventory where there is also a foreign key referencing item_id and this forward engineered just fine.

Any ideas?
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5211 on: November 18, 2013, 09:54:42 am »

I need some help with MySQL. I am creating a backend for a faux e-commerce site and am having some issues with adding a specific table.

I am using MySQL Workbench.

Basically I have a table for users containing a primary key called username, I also have a table for items in the store containing a primary key called item_id. Now I want to create a table called orders that amongst other things contain foreign keys pointing to the username and the item id. When forward engineering this, workbench throws the following extremely descriptive error.

"ERROR: Error 1005: Can't create table 'mydb.ORDERS' (errno: 121)"

I understand that this has something to do with the foreign keys and from google the reason seems to be foreign keys named the same as the constraint but I use the same thing for a table called Inventory where there is also a foreign key referencing item_id and this forward engineered just fine.

Any ideas?
1. Workbench is buggy as hell. Used to use it, but abandoned it. Beware of losing large amounts of work.
2. To be on the safe side: Make sure that all Foreign keys/constraints and column names are unique (you can't have a foreign key called "item_id" if you have a column with that name.


If that's not it, can you post the SQL that it outputs?


Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5212 on: November 18, 2013, 04:15:52 pm »

I need some help with MySQL. I am creating a backend for a faux e-commerce site and am having some issues with adding a specific table.

I am using MySQL Workbench.

Basically I have a table for users containing a primary key called username, I also have a table for items in the store containing a primary key called item_id. Now I want to create a table called orders that amongst other things contain foreign keys pointing to the username and the item id. When forward engineering this, workbench throws the following extremely descriptive error.

"ERROR: Error 1005: Can't create table 'mydb.ORDERS' (errno: 121)"

I understand that this has something to do with the foreign keys and from google the reason seems to be foreign keys named the same as the constraint but I use the same thing for a table called Inventory where there is also a foreign key referencing item_id and this forward engineered just fine.

Any ideas?
1. Workbench is buggy as hell. Used to use it, but abandoned it. Beware of losing large amounts of work.
2. To be on the safe side: Make sure that all Foreign keys/constraints and column names are unique (you can't have a foreign key called "item_id" if you have a column with that name.


If that's not it, can you post the SQL that it outputs?

Yeah there is obviously something I am not getting. I am a real SQL noob.

Here is the output from trying to forward engineer it. The output from Workbench is (it now changed the error type from 121 to 150).

Quote
Executing SQL script in server
ERROR: Error 1005: Can't create table 'mydb.ORDERS' (errno: 150)


CREATE  TABLE IF NOT EXISTS `mydb`.`ORDERS` (
  `order_id` INT NOT NULL AUTO_INCREMENT ,
  `amount` INT NOT NULL ,
  `cost` FLOAT NOT NULL ,
  `item_id` INT NOT NULL ,
  `username` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`order_id`) ,
  INDEX `item_id` (`item_id` ASC) ,
  INDEX `username` (`username` ASC) ,
  CONSTRAINT `item_id`
    FOREIGN KEY (`item_id` )
    REFERENCES `mydb`.`ITEM` (`item_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `username`
    FOREIGN KEY (`username` )
    REFERENCES `mydb`.`USERS` (`username` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

SQL script execution finished: statements: 12 succeeded, 1 failed

On (2) of your suggestion is where I am getting a bit stuck, if I understand correctly you mean I can't create an column called item_id and then a foreign key that points to item_id of another table. But that is exactly how I have done it on my Inventory table where I also reference item_id, from what I can see there are no major differences between my inventory and my orders tables except that the orders table has two foreign keys instead of one.

What I have already are three tables, one called Users, holding all the accounts, one called items where information about each item in the store is held and one called inventory that basically keeps track of how many of specific items I have and that will hold some other info in the future (like next estimated delivery of new stock).
What I want to add is the Orders table where I can hold information about ordered items with two foreign keys, one pointing at the item_id from ITEM and one pointing at the username from USERS.

EDIT: Sorry for rambling, I am a bit tired :p

EDITEDIT: I think I am misunderstanding how foreign keys are supposed to be used, I think I may be doing something fundamentally wrong here. I think I'll spend some time reading up on them because at the moment my brain is simply thinking of them as a MySQL version of pointers which seems to not be quite the case.

« Last Edit: November 18, 2013, 04:18:12 pm by Aptus »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5213 on: November 18, 2013, 05:49:52 pm »



On (2) of your suggestion is where I am getting a bit stuck, if I understand correctly you mean I can't create an column called item_id and then a foreign key that points to item_id of another table. But that is exactly how I have done it on my Inventory table where I also reference item_id, from what I can see there are no major differences between my inventory and my orders tables except that the orders table has two foreign keys instead of one.
Ah, thought so. Try this:

Code: [Select]
  INDEX `item_id_index` (`item_id` ASC) ,
  INDEX `username_index` (`username` ASC) ,
  CONSTRAINT `item_id_constraint`
    FOREIGN KEY (`item_id_index` )
    REFERENCES `mydb`.`ITEM` (`item_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `username_constraint`
    FOREIGN KEY (`username_index` )
    REFERENCES `mydb`.`USERS` (`username` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)

See what I did there? Indices and Constraints have names, too, and they should not overlap (be the same as) with names of columns (or each other). I thought Workbench automatically made unique names for new constraints? Hmz.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5214 on: November 19, 2013, 02:25:24 am »

Every time I see talk about databases, I think, "I should actually learn how to use databases. Today could be that day."

But every time, once I try starting, I think, "Today is not that day."

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5215 on: November 19, 2013, 03:12:53 am »

... They're not that hard. Foreign key constraints are actually the hardest part of the beginners' chapter, which is where I stopped. I couldn't create a stored procedure to save my life.

Databases are just like programming: Try a lot, fail, google your error messages, try again.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Aptus

  • Bay Watcher
  • Indeed ôo
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5216 on: November 19, 2013, 03:18:44 am »



On (2) of your suggestion is where I am getting a bit stuck, if I understand correctly you mean I can't create an column called item_id and then a foreign key that points to item_id of another table. But that is exactly how I have done it on my Inventory table where I also reference item_id, from what I can see there are no major differences between my inventory and my orders tables except that the orders table has two foreign keys instead of one.
Ah, thought so. Try this:

Code: [Select]
  INDEX `item_id_index` (`item_id` ASC) ,
  INDEX `username_index` (`username` ASC) ,
  CONSTRAINT `item_id_constraint`
    FOREIGN KEY (`item_id_index` )
    REFERENCES `mydb`.`ITEM` (`item_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `username_constraint`
    FOREIGN KEY (`username_index` )
    REFERENCES `mydb`.`USERS` (`username` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)

See what I did there? Indices and Constraints have names, too, and they should not overlap (be the same as) with names of columns (or each other). I thought Workbench automatically made unique names for new constraints? Hmz.

Ahh now that makes sense. Thank you!
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5217 on: November 19, 2013, 07:48:12 am »

I couldn't create a stored procedure to save my life.

Stored procedures were something we gave up on at work. They were difficult to maintain because they weren't in source control and needed you to modify the database itself to create/modify, and a lot of the legacy ones had disturbing amounts of business logic in them anyway. In the end, it was easier and more efficient to keep the SQL as small as possible and keep it in-code.

There are ways to automate the modification of SPs and keep them in source control of course, but we just decided it was simpler to abandon them entirely. For us, keeping it in code also made for much easier local testing of changes and kept the feedback cycle small as possible.

Stored procedures are probably more suited for giant blocks of SQL, so there's not much point if all the SQL statements are small and highly targeted, but for our domain lots of small SQL statements made more sense and we found was more efficient.
« Last Edit: November 19, 2013, 08:07:39 am by MorleyDev »
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5218 on: November 19, 2013, 08:23:45 am »

Foreign key constraints are actually the hardest part of the beginners' chapter, which is where I stopped.

Same here, although I don't bother with formal foreign key constraints in my database tables.  In fact, I was under the impression that MySQL didn't even support such a thing for a very long time.  Maybe it was just certain storage engines?

Quote
I couldn't create a stored procedure to save my life.

Me neither.  The very rare few times we came across situations where we thought we needed these at work, we ended up abandoning them in favor of just doing it in PHP instead.

Quote
Databases are just like programming: Try a lot, fail, google your error messages, try again.

Pretty much this, except if you're using MySQL, expect the error messages to be almost less than helpful.  :)  I don't know if something like SQLServer is any better though.
Logged
Through pain, I find wisdom.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5219 on: November 19, 2013, 08:51:59 am »

SQL 0901
: Something broke and you can't fix it!


;D
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 346 347 [348] 349 350 ... 796