L-functions and character sums for quadratic forms (I)